Re: psycopg2 adaptation for UUIDs

ibu ☉ <ibu-qs259T/[email protected]>
Newsgroups gmane.comp.python.db.psycopg.devel
Organization http://ibu.radempa.de
Message-ID <[email protected]>
Dated 2008-09-19 9:27 , Federico Di Gregorio <fog-NGVKUo/i/[email protected]> said:
> Starting from your code I added UUID support in psycopg2 (pushed to bzr
> trunk right now). Just:
>
> import psycopg2.extras
> psycopg2.extras.register_uuid()
Hi,

some time ago you added UUID support. This also works for python lists, 
which become adapted to UUID[] arrays in postgres. The opposite 
direction (postgres arrays to python lists) still requires something 
like this:

import uuid
UUID_ = psycopg2.extensions.new_type((2951,), "UUID[]",
        lambda s, cursor: [uuid.UUID(i) for i in str(s[1:-1]).split(',')])
psycopg2.extensions.register_type(UUID_)

Maybe this is of use to somebody, and maybe there is also place on the 
wishlist for native support of uuid arrays.

In the meanwhile the above 6 lines work fabulous.

Thanks for psycopg2,
ibu
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.