[PyGreSQL] datetime.date and float and nan

Christoph Zwerschke cito at online.de
Sat Jul 16 10:32:42 EDT 2011


Am 16.07.2011 15:29 schrieb Maxim Yegorushkin:
> This patch extends float handling by supporting nan and inf values along
> with a new unit test. It basically always quotes floats to avoid isinf()
> and isnan() checks for each and every float value.

Hm, this may work with older Postgres versions, but it's a bit unclean 
since it puts quotes arounds normal floats where they do not belong, and 
since it relies on the string representation of NaN and Inf in Python 
which may differ for different Python versions and is definitely 
different from their official representation in Postgres (e.g. 'inf' 
instead of 'Infinity' and 'nan' instead of 'NaN'). Newer Postgres 
versions may not be so sloppy concerning the input, and indeed Postgres 
9.0 does not allow writing 'inf' insted of 'Infinity'. We should better 
produce the proper SQL, i.e. the official names with proper case even 
though Postgres currently is case-insensitive on input, and we should 
not put quotes around numbers.

> With regards to date support, I am thinking of handling date and
> datetime similar to decimal, that is, to convert strings to date and
> datetime when reading rowsets, so that user code does not have to
> convert strings to dates. Does it make sense?

This is http://trac.vex.net:8000/pgtracker/ticket/28

But I think we should make it configurable so that old code will not be 
broken. The default could be strings in 4.x, and then dates in 5.x.

-- Christoph


More information about the PyGreSQL mailing list