Re: problem with timezone parsing
Federico Di Gregorio <fog-NGVKUo/i/[email protected]>
| Newsgroups | gmane.comp.python.db.psycopg.devel |
|---|---|
| Organization | initd.org |
| Message-ID | <[email protected]> |
Il giorno mar, 17/02/2009 alle 16.57 +0100, Karsten Hilbert ha scritto: > 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 ...) Yes, just don't pass that parameter or pass None. > 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). If you know the oid you can hard-code it into your code. > 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. Yes, the values are the OIDs. > Thereby the second question can be answered yes but needs > reconfirmation that re-using those OIDs is reasonably safe ? It is completely safe. They are generated from your PostgreSQL headers and guaranteed to be stable. federico -- Federico Di Gregorio http://people.initd.org/fog Debian GNU/Linux Developer [email protected] INIT.D Developer fog-NGVKUo/i/[email protected] I did appreciate the irony that I was whining about encoding issues on a mailing list that was unable to show those chars, too. -- Antti S. Lankila to mono-devel-list@ _______________________________________________ Psycopg mailing list Psycopg-IAPFreCvJWPBWskQ1e/[email protected] http://lists.initd.org/mailman/listinfo/psycopg
signature.asc
(application/pgp-signature, 197 B)
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) iEYEABECAAYFAkma3zUACgkQvcCgrgZGjevlKACgoyiw8MSTyeJQ5sbK/1iuaRlq GXcAniiSYiZTEwamfjvAJMXTq45+e6JA =fuFd -----END PGP SIGNATURE-----