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 non-OR
On Jan 7, 2013, at 10:06 AM, Hans Lellelid wrote:
> Thanks for the response. I am actually trying to do an ARRAY(INET) here, and
> while pscopg2 does have a register_inet() it does not seem to (fully?) work
> with arrays. The return casting works fine, but I get type "is of type
> inet[] but
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 ac
Thanks for the response. I am actually trying to do an ARRAY(INET) here,
and while pscopg2 does have a register_inet() it does not seem to (fully?)
work with arrays. The return casting works fine, but I get type "is of
type inet[] but expression is of type text[]" when trying to bind.
The fix
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
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 lookin
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:
#
s = Session(bind=engine
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 va
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
https://gist.github
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 typ
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 strin
OK well there's a lot of unfortunate turns on this one, at the core is that
psycopg2 by default doesn't know how to accept a list of UUIDs.The
postgresql.UUID() type in SQLAlchemy takes the easy approach and just converts
the value to a string, provided you pass the as_uuid=True flag to it.
12 matches
Mail list logo