[sqlalchemy] [Postgres] Querying an array

2011-02-03 Thread aj
Running Sqlalchemy 0.5.8 (can't upgrade right now) with Postgres 8.1.X. A table contains an array column: users text[] In SQL I would query select ...where 'jim' = ANY(users) How would I query this using the ORM layer? -aj -- You received this message because you are subscribed to the

[sqlalchemy] Is it possible to know in advance elements that will be cascade-deleted?

2011-02-03 Thread neurino
Can I show the user a warning like: if you delete this item also [list of other items] will be removed whichever is the item? I was using something like this: import inspect def get_items(item_to_be_deleted): get_items(item_to_be_deleted) - [(child_item_name,

Re: [sqlalchemy] StaleDataError when deleting through an association_proxy

2011-02-03 Thread Andronikos Nedos
assuming Dtable.data_id references BTable. There's a few ways to go about this. The usual way to alter what gets deleted where in a flush is to use SessionExtension.before_flush() to figure out whatever needs to happen based on the pending state of things, using Session.delete() to

Re: [sqlalchemy] [Postgres] Querying an array

2011-02-03 Thread Michael Bayer
you can emit ANY(...) using func.any(table.c.users) On Feb 3, 2011, at 3:25 AM, aj wrote: Running Sqlalchemy 0.5.8 (can't upgrade right now) with Postgres 8.1.X. A table contains an array column: users text[] In SQL I would query select ...where 'jim' = ANY(users) How would I

[sqlalchemy] Re: sqlalchemy, sequel server 2008, and python 3

2011-02-03 Thread Jonathan Cox
Thank you. I appreciate your taking the time to address very basic questions. I've managed to install everything successfully. Now to get pyodbc to actually talk to my server... -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group,

Re: [sqlalchemy] Is it possible to know in advance elements that will be cascade-deleted?

2011-02-03 Thread Michael Bayer
you could use the mapper's cascade function from sqlalchemy.orm import object_mapper, instance_state m = object_mapper(item_to_be_deleted) for rec in m.cascade_iterator(delete, instance_state(item_to_be_deleted)): obj = rec[0] print item will be deleted !, obj On Feb 3, 2011, at 6:15 AM,

[sqlalchemy] How to tweak pylint for SA models?

2011-02-03 Thread Ralph Heinkel
Hi, we are about fitting pylint's configuration to work with out software. One problem area is when we access SA models. Due to all attributes being set dynamically pylint assumes that we want to access non-existing attributes and reports either E1101 or E1103 error codes. Does anyone have

[sqlalchemy] Re: Is it possible to know in advance elements that will be cascade-deleted?

2011-02-03 Thread neurino
That is great! Just for eventual followers I fix imports: from sqlalchemy.orm import object_mapper from sqlalchemy.orm.attributes import instance_state m = object_mapper(item_to_be_deleted) for rec in m.cascade_iterator(delete, instance_state(item_to_be_deleted)): obj =

Re: [sqlalchemy] Re: Is it possible to know in advance elements that will be cascade-deleted?

2011-02-03 Thread Michael Bayer
On Feb 3, 2011, at 11:58 AM, neurino wrote: That is great! Just for eventual followers I fix imports: from sqlalchemy.orm import object_mapper from sqlalchemy.orm.attributes import instance_state m = object_mapper(item_to_be_deleted) for rec in m.cascade_iterator(delete,

[sqlalchemy] FOR UPDATE OF

2011-02-03 Thread Kent
session.query(Cls).with_lockmode('update') will render FOR UPDATE Is there a way to render FOR UPDATE OF table or column? I ask because postgresql complains about locking FOR UPDATE when given an outer join. BUT, it is happy if you say FOR UPDATE OF left hand table given an outer join. Thanks

Re: [sqlalchemy] FOR UPDATE OF

2011-02-03 Thread Michael Bayer
Theres a ticket to support database-specific FOR UPDATE options in trac, for now you'd need to use the usual routes into modifying the select statement (@compiles for the select() construct, place extra _state on the select() object read by your function, regexp it into the string, subclass

[sqlalchemy] Re: FOR UPDATE OF

2011-02-03 Thread Kent
I'm not especially familiar with this code. I understand subclassing query and adding @_generative method to capture the state, but could you point to an example or expound a little for how I get my query class to add to the end of the select(). I'm not /*replacing* / _compile_context I hope,

[sqlalchemy] Re: FOR UPDATE OF

2011-02-03 Thread Kent
Here is a crude outline (need to properly escape table name, etc.), of what I think might work, and it seems to render properly, but crashes with: File /home/rarch/tg2env/lib/python2.6/site-packages/ SQLAlchemy-0.6.4.2kbdev-py2.6-linux-x86_64.egg/sqlalchemy/engine/ default.py, line 353, in

Re: [sqlalchemy] Re: FOR UPDATE OF

2011-02-03 Thread Michael Bayer
Was hoping for the patch :). Its not that hard.Easier than the workaround, except for writing the tests, which is only hard because it involves faithfully copying the style of how we do our other tests. Anyway the subclass query approach means you'd wrap _compile_context, get the return

Re: [sqlalchemy] Re: FOR UPDATE OF

2011-02-03 Thread Michael Bayer
oh OK this is a little simpler than what I had in mind, you just have to add the mixin expression.Executable to your ForUpdateOf class. On Feb 3, 2011, at 9:05 PM, Kent wrote: Here is a crude outline (need to properly escape table name, etc.), of what I think might work, and it seems to

[sqlalchemy] Re: FOR UPDATE OF

2011-02-03 Thread Kent
Yeah, I wanted to apologize because my heart wants to contribute to the project (really), but I'm working overtime like mad swamped because our product is live in use now and I've got a backload of tickets to solve! I also feel my level of understanding currently is more hacking than

[sqlalchemy] MapperExtension#after_insert behavior

2011-02-03 Thread Ryan
I'm using MapperExtension#after_insert and realizing that this callback fires when a record has been inserted into a transaction, but before the session is actually committed. I'd like an after_insert callback that fires after commit/once the record physically resides in the database. Any