I am looking to adapt this code for a related array/type issue. The code
from https://gist.github.com/4433940 works just fine for me (as expected)
when building/executing the stmt directly, but not when using the ORM.
When row is created using ORM, like this:
# snip
s =
this is ticket http://www.sqlalchemy.org/trac/ticket/2648 and cannot be worked
around at this time. If you're working with arrays of UUID I'd recommend
using psycopg2 type processors, as the previous poster has had success with.
On Jan 7, 2013, at 9:39 AM, Hans Lellelid wrote:
I am
correction, this seems to work, though will try to improve:
class UUID_ARRAY(TypeDecorator):
impl = ARRAY(UUID, dimensions=1)
def bind_expression(self, bindvalue):
if bindvalue.callable:
val = bindvalue.callable()
else:
val = bindvalue.value
change again, that doesn't work.
Upon reflection, I think the case here is that there's no alternative but to
make sure psycopg2 can properly format the contents of the ARRAY itself. This
is because SQLAlchemy is producing a completed INSERT statement for
preparation, without the parameters
Thanks for the follow up.
Upon further reading/reflection, I discovered that wrapping my string IP
address values in the psycopg2.extras.Inet object and then passing that in
-- and executing psycopg2.extras.register_inet() as with the UUID example
-- seems to work fine for both ORM and
Hi all,
I'm experimenting a bit with postgresql arrays of uuid's.
Unfortunately I'm running into a bug or I'm not really understanding
it :-)
My schema definition is as follow:
table = Table('example', metadata,
Column('timestamp', DateTime(timezone=False), primary_key=True),
Thanks for the detailed response! Inserting the values seems to work
fine now. Only retrieving them again doesn't work.
I've updated the gist at https://gist.github.com/4433940
The problem seems that psycopg2 now returns the array as a string
({uuid1, uuid2}) and sqlalchemy iterates over the
psycopg2 does have some adapters for this:
http://initd.org/psycopg/docs/extras.html?highlight=uuid#uuid-data-type
ideally using those would work transparently with ARRAY types, but its not
clear if they do or not. They should, or if not you'd probably need to
build a more comprehensive
Again, thanks for the detailed response! I went with the
psycopg2.extras.register_uuid() method and that works without problems
for now.
I did have to remove the as_uuid=True since psycopg2 already returned
it as an uuid type.
For future references the working test code is here
that adapter works both ways, so you can drop the custom type completely:
table = Table('example_2', metadata,
Column('timestamp', DateTime(timezone=False), primary_key=True),
Column('num', Integer),
Column('guids', ARRAY(UUID, dimensions=1))
)
On Jan 2, 2013, at 2:10 PM, Michael
10 matches
Mail list logo