Re: Problem with locale and psycopg2
Karsten Hilbert <[email protected]>
| Newsgroups | gmane.comp.python.db.psycopg.devel |
|---|---|
| Message-ID | <[email protected]> |
On Sun, Aug 30, 2009 at 01:37:39PM +0200, dick wrote:
> We are porting a big application that still uses psycopg1 to psycopg2.
>
> Now I encountered the following problem with locales and storing of time:
>
> invalid input syntax for type time: "09:00:00,000000"
>
> You may notice the comma (,) in front of the millisecond part. Now I have seen
> this problem in the past (2006) with a slightly different form (timestamp), but
> off course it should (depending on the locale) accept this time as valid!
It is annoying and ultimately a failure of PostgreSQL which
I did report there, too. GNUmed solves it like this:
class cAdapterMxDateTime(object):
def __init__(self, dt):
self.__dt = dt
def getquoted(self):
# under some locale settings the mx.DateTime ISO formatter
# will insert "," into the ISO string,
# while this is allowed per the ISO8601 spec PostgreSQL
# cannot currently handle that,
# so map those "," to "." to make things work:
return mxDT.ISO.str(self.__dt).replace(',', '.')
try:
import mx.DateTime as mxDT
psycopg2.extensions.register_adapter(mxDT.DateTimeType, cAdapterMxDateTime)
except ImportError:
_log.warning('cannot import mx.DateTime')
Karsten
--
GPG key ID E4071346 @ wwwkeys.pgp.net
E167 67FD A291 2BEA 73BD 4537 78B9 A9F9 E407 1346