Re: Ability to plug-in/override Decimal Handler ?

Federico Di Gregorio <fog-NGVKUo/i/[email protected]>
Newsgroups gmane.comp.python.db.psycopg.devel
Organization initd.org
Message-ID <1249824935.9296.20.camel@erin>
Il giorno gio, 30/07/2009 alle 15.12 -0400, Stef Telford ha scritto:
> Hey Everyone,
>     I haven't ever had much recourse to email the mailing list, as I am 
> mostly one of those ORM folks that uses the upper layer. Apologies in 
> advance for that ;) However, I have noticed that during bulk operations 
> (mostly instantiations) using the ORM that the decimal.Decimal is slow. 
> I mean 400seconds slow, when compared to using gmpy.mpq which ends up 
> running in 50seconds.
[snip]

Probably you already found out in the ML archives but the right way to
do this is to register a typecaster for the interested OIDS:

import gmpy
import psycopg2.extensions

psycopg2.extensions.MPQ = psycopg2.extensions.new_type(
	(1700,), "MPQ",
	lambda data, curs: gmpy.mpq(data))

psycopg2.extensions.register_type(psycopg2.extensions.MPQ)

where assigning the new type to psycopg2.extensions is customary and
"1700" is the OID of the decimal type in PostgreSQL. Note that I didn't
run the code so it can contain typos but should be enough to get you
started.

Hope this helps,
federico

-- 
Federico Di Gregorio                         http://people.initd.org/fog
Debian GNU/Linux Developer                                [email protected]
INIT.D Developer                                           fog-NGVKUo/i/[email protected]
  Those who do not study Lisp are doomed to reimplement it. Poorly.
                                     -- from Karl M. Hegbloom .signature

_______________________________________________
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)

iEYEABECAAYFAkp+0KcACgkQvcCgrgZGjevJXQCfZSOWEIh7/hstaAPlWG7R1O0q
JakAn2hxdrWbbld2YSg41hYG+y8GmTaJ
=fkkl
-----END PGP SIGNATURE-----
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.