Re: "ProgrammingError: can't adapt" when passing arguments to cursor.execute
Federico Di Gregorio <fog-NGVKUo/i/[email protected]>
| Newsgroups | gmane.comp.python.db.psycopg.devel |
|---|---|
| Organization | initd.org |
| Message-ID | <1258747544.3070.12.camel@mila> |
Il giorno ven, 20/11/2009 alle 11.53 -0800, William Carithers ha
scritto:
> Hi Federico,
>
> I thought this problem might need you to solve. The problem is probably the
> numpy.float32 . Can I fix this with a cast? Would float(...the thing that is
> numpy.float32...) work?
That's right. The best thing you can do is to register an adapter for
the numpy.float32 type:
class numpy_float32_adapter(object):
"""Adapt numpy's float32 type to PostgreSQL's float."""
def __init__(self, f):
self._f = f
def prepare(self, conn):
pass
def getquoted(self):
return str(self._f)
__str__ = getquoted
psycopg2.extensions.register_adapter(numpy.float32, numpy_float32_adapter)
You probably need to change the getquoted() method to something
different from a plain str() call, depending on how the float32 type
behaves.
federico
--
Federico Di Gregorio http://people.initd.org/fog
Debian GNU/Linux Developer [email protected]
INIT.D Developer fog-NGVKUo/i/[email protected]
In some countries (e.g., Germany) even many brands of toilet paper have
format A6. [http://www.cl.cam.ac.uk/~mgk25/iso-paper.html]
_______________________________________________
Psycopg mailing list
Psycopg-IAPFreCvJWPBWskQ1e/[email protected]
http://lists.initd.org/mailman/listinfo/psycopg
signature.asc
(application/pgp-signature, 198 B)
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) iEYEABECAAYFAksG9pgACgkQvcCgrgZGjevVhQCgw2p8TvER04vIEx1am6BvhVIy 5/UAoJ/9WTUjuOeHkS9IequR2lzIPUwW =3l4h -----END PGP SIGNATURE-----