Re: Howto explicit cast types for PG-functions?
Federico Di Gregorio <fog-NGVKUo/i/[email protected]>
| Newsgroups | gmane.comp.python.db.psycopg.devel |
|---|---|
| Organization | initd.org |
| Message-ID | <1243243538.11089.21.camel@erin> |
Il giorno dom, 24/05/2009 alle 14.57 -0600, Christopher D. Kyle ha scritto: > Hi Martin, > > I'm new to psycopg but I think you are on the right track using the > pyformat for assigning your variables in the execute statement. As I see > it , you simply need to list your formatting in the correspondingly > C-style. > > %(var)s - means format as a valid PostgreSQL formatted string (e.i.: > 'single quote string' ) > %(var)f - means format as a valid PostgreSQL formatted float (e.i.: 3.14 ) > %(var)d - means format as a valid PostgreSQL formatted integer (e.i.: 42) No no no. Never do that. The format should always be "s" because it is a marker, not a real format. Starting from 2.1 psycopg will throw a warning on wrong marker usage. The right way to do what Martin wants is to create a custom type adapter (maybe overwriting the default one for integers). See the examples/ directory for example of both adapters (Python->PostgreSQL) and typecasters (PostgreSQL->Python). federico -- Federico Di Gregorio http://people.initd.org/fog Debian GNU/Linux Developer [email protected] INIT.D Developer fog-NGVKUo/i/[email protected] Credo fermamente che da qualche parte, in una scatola ci sia un gatto che non è vivo ne morto. Credo anche che se i fisici non si sbrigano a dargli una scatoletta, ben presto sarà solo morto. -- adattato da una frase di Sam Black Crow _______________________________________________ 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) iEYEABECAAYFAkoaZAwACgkQvcCgrgZGjet7SACfXmJoREo9E8QNBWyioiuQWABP TM0AoNZ7J9RtEw39VNoEguD2Crc4IBqX =4Vzm -----END PGP SIGNATURE-----