Re: "Naked" typecast functions?
Peter Sabaini <peter-Di7OsXwWAkqzZXS1Dc/[email protected]> Thu, 22 Apr 2010 10:07:26 +0200
| Newsgroups | gmane.comp.python.db.psycopg.devel |
|---|---|
| Message-ID | <[email protected]> |
On Wed, 2010-04-21 at 22:39 +0200, Federico Di Gregorio wrote:
> On 21/04/2010 17:28, Peter Sabaini wrote:
> > Is it possible to use the various typecasting functions of psycopg2 in a
> > non-implicit manner? AFAICT the typecasters get called automatically
> > depending on the parameters passed in to .execute(). Can I call those
> > typecasters without a cursor object?
>
> You can; just invoke the type object as in
>
> psycopg2.NUMBER("12.34", None)
Ah, I actually tried this but passed in an integer, which fails
silently :-)
Does this also work with arrays? (There seems to something there in the
C implementation, eg. psycopg2._psycopg.STRINGARRAY(), but I guess this
works the other way around;
>>> psycopg2._psycopg.STRINGARRAY("{a, b}", None)
['a', ' b']
)
Thanks,
peter.
> note that the second argument ought to be a cursor but you can safetly
> pass None to almost all the typecasters except for the UNICODE one
> because it needs some information about the encoding of the string and
> will try to get it from cursor.connection.
>
> federico
>
> _______________________________________________
> Psycopg mailing list
> Psycopg-IAPFreCvJWPBWskQ1e/[email protected]
> http://lists.initd.org/mailman/listinfo/psycopg