Re: problem with timezone parsing

Karsten Hilbert <[email protected]>
Newsgroups gmane.comp.python.db.psycopg.devel
Message-ID <[email protected]>
On Tue, Feb 17, 2009 at 11:39:30PM +0900, James Henstridge wrote:

> >> As mentioned before, if you want behaviour different to this I'd
> >> suggest installing an alternative typecaster.  That would also let you
> >> fix the busted time zone parsing for released versions of psycopg2.
> >
> > Is there a way to install a custom typecaster, then from
> > inside which letting the default typecaster handle things
> > but listen for the above exception and handle that
> > appropriately ?
> 
> You can call the other typecaster directly:
> 
>     timestamp = psycopg2.DATETIME(some_string, cursor)
> 
> Your typecast function will be passed the string and cursor as arguments.

Ah, OK, thanks. Now, two more questions ;-)

Is there a way to install a module wide type caster ?

 Per-connection type casters were introduced not too long
 ago (and the examples show how to use them) but can we
 still get the per-psycopg2 instance casters? The
 register_type() seems to want either a connection or a
 cursor. The "help(psycopg2.extensions.register_type)"
 interactive help doesn't say whether the connection/cursor
 argument is mandatory (in fact, it doesn't mention it at
 all ...)

Is there a way to not need to access the DB (for learning
the type OID) and still use new_type (which seems a
prerequisite for register_type).

 It seems possible as one might assume the OID for
 "timestamp with time zone" to be fixed - but I remember
 reading on the PG list that that isn't guarantueed for all
 times. However, UNICODE and UNICODEARRAY do seem to assume
 a fixed type OID (because they can be register_type()ed w/o
 needing to determince the type OID). So I'd try to be
 clever and deduce the OID from psycopg2.DATETIME.values but
 unfortunately there is no documentation as to what those
 values are. Digging in psycopg/pgtypes.h reveals that those
 are, indeed, the needed OIDs.

Thereby the second question can be answered yes but needs
reconfirmation that re-using those OIDs is reasonably safe ?

Karsten
-- 
GPG key ID E4071346 @ wwwkeys.pgp.net
E167 67FD A291 2BEA 73BD  4537 78B9 A9F9 E407 1346
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.