[sqlalchemy] How can i use insert/update with transactions

2009-10-29 Thread edward
Hi,I can't use transaction with class Insert()/Update,someone can help me ?thanks! When i run Insert().execute() then will auto commit the transaction,I don't want it auto commit... code import sqlalchemy as sa from sqlalchemy import MetaData from

[sqlalchemy] Identical column names in parent and child classes with joined-table inheritance

2009-10-29 Thread bojanb
Hi, Can I have identical column names in both parent and child classes that are part of a joined-table inheritance? These are simply created, created_by, modified, modified_by columns that are populated by defaults defined for them (ie. default, server_default, onupdate). The values are written

[sqlalchemy] Re: How can i use insert/update with transactions

2009-10-29 Thread Mike Conley
Looks like you are trying to mix ORM and SQL expression constructs. Also, Insert() objects should be constructed via the insert() function. Try this conn = session.connection() # get handle to the session's connection t = conn.begin() res = conn.execute(insert(t_table).values(id=None,pv=6))

[sqlalchemy] Using database-level cascade when issuing Session.delete

2009-10-29 Thread Igor Katson
Hello! I am stuck when trying to delete an object, on which there are references. I have a database-level ON DELETE CASCADE rule, but when issuing Session.delete, it raises an IntegrityError, cause sqlalchemy first tries to SET NULL the references on all the children. If I use cascade='all,

[sqlalchemy] Re: SA 0.5.6 how to create a sequence on a non-primary key field with postgres backend

2009-10-29 Thread Michael Bayer
sim wrote: creation_order = Column('creation_order', PGBigInteger, Sequence ('creation_order_seq')) this works fine for me and this is covered in test cases too. from sqlalchemy import * from sqlalchemy.databases.postgres import PGBigInteger engine =

[sqlalchemy] Re: Using database-level cascade when issuing Session.delete

2009-10-29 Thread Michael Bayer
Igor Katson wrote: Hello! I am stuck when trying to delete an object, on which there are references. I have a database-level ON DELETE CASCADE rule, but when issuing Session.delete, it raises an IntegrityError, cause sqlalchemy first tries to SET NULL the references on all the children. If

[sqlalchemy] Re: A problem with SQLA'a referential integrity behavior, deferred constraints and PostgreSQL

2009-10-29 Thread Michael Bayer
bojanb wrote: SQLAlchemy's unit of work attempts to set it to None during the flush. Doesn't that imply that ondelete='RESTRICT' is not honored by UoW? how would the UOW honor RESTRICT ? if you tell it to delete a parent, and you didn't tell it to delete a child, and you have a

[sqlalchemy] issue with group_concat and op

2009-10-29 Thread Thomas Drake
Hi, I'm running into an issue in 0.5.2 and 0.6.1beta where it appears that group_concat and .op are producing incorrect SQL. q = session.query(func.group_concat(unionq.c.status.op('order by')(q.c.stop)) where unionq is essentially a union_all().subquery() of several queries.

[sqlalchemy] Re: issue with group_concat and op

2009-10-29 Thread Thomas Drake
Wow, my above example sucked. Here's something close to what I'm actually using: qs = ... qunion = qs[0].union_all(*qs[1:]).subquery() joined = session.query( KnownComponents.name, qunion, func.group_concat(qunion.c.status.op('order

[sqlalchemy] Re: issue with group_concat and op

2009-10-29 Thread Michael Bayer
Thomas Drake wrote: Wow, my above example sucked. Here's something close to what I'm actually using: qs = ... qunion = qs[0].union_all(*qs[1:]).subquery() joined = session.query( KnownComponents.name, qunion,

[sqlalchemy] Re: A problem with SQLA'a referential integrity behavior, deferred constraints and PostgreSQL

2009-10-29 Thread bojanb
On Oct 29, 5:32 pm, Michael Bayer mike...@zzzcomputing.com wrote: how would the UOW honor RESTRICT ?  if you tell it to delete a parent, and you didn't tell it to delete a child, and you have a non-nullable FK or RESTRICT, you'd expect it tothrow an error, right ?   isn't that what

[sqlalchemy] Re: A problem with SQLA'a referential integrity behavior, deferred constraints and PostgreSQL

2009-10-29 Thread Michael Bayer
bojanb wrote: On Oct 29, 5:32 pm, Michael Bayer mike...@zzzcomputing.com wrote: how would the UOW honor RESTRICT ?  if you tell it to delete a parent, and you didn't tell it to delete a child, and you have a non-nullable FK or RESTRICT, you'd expect it tothrow an error, right ?   isn't

[sqlalchemy] merge without merging related objects

2009-10-29 Thread Tvrtko
Hi, is it possible to merge an object back to session, but without merging the entire tree of related objects. Just this one root object. I'm trying to implement caching for my user identity framework and I don't want to merge back the entire tree of objects reachable from the user entity. I

[sqlalchemy] Re: merge without merging related objects

2009-10-29 Thread Michael Bayer
Tvrtko wrote: Hi, is it possible to merge an object back to session, but without merging the entire tree of related objects. Just this one root object. the general way is to disable merge cascade on the relation(), using cascade='save-update' or cascade=None I created a new user instance

[sqlalchemy] Re: A problem with SQLA'a referential integrity behavior, deferred constraints and PostgreSQL

2009-10-29 Thread bojanb
Yes, the passive_deletes='all' solves this, the trick is to put it in the backref (I was putting it in the forward relation). On Oct 29, 8:29 pm, Michael Bayer mike...@zzzcomputing.com wrote: Michael Bayer wrote: bojanbwrote: On Oct 29, 5:32 pm, Michael Bayer mike...@zzzcomputing.com

[sqlalchemy] Re: merge without merging related objects

2009-10-29 Thread Tvrtko
On Oct 29, 8:44 pm, Michael Bayer mike...@zzzcomputing.com wrote: Tvrtko wrote: Hi, is it possible to merge an object back to session, but without merging the entire tree of related objects. Just this one root object. the general way is to disable merge cascade on the relation(), using

[sqlalchemy] Re: merge without merging related objects

2009-10-29 Thread Michael Bayer
Tvrtko wrote: transient objects can be merged.  They get added to the session and enter the pending state. I get: InvalidRequestError: merge() with dont_load=True option does not support objects transient (i.e. unpersisted) objects. flush() all changes on mapped instances before

[sqlalchemy] Re: merge without merging related objects

2009-10-29 Thread Tvrtko
On Oct 29, 9:33 pm, Michael Bayer mike...@zzzcomputing.com wrote: Tvrtko wrote: transient objects can be merged.  They get added to the session and enter the pending state. I get: InvalidRequestError: merge() with dont_load=True option does not support objects transient (i.e.

[sqlalchemy] Re: issue with group_concat and op

2009-10-29 Thread Thomas Drake
Kickass! This is fantastic. Thanks! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to

[sqlalchemy] custom order by

2009-10-29 Thread Thomas Drake
Heyo, Is there any way to specify a particular ordering on a column with the order by clause (or otherwise)? Something like: session.query(People).order_by(People.name, ['rick', 'james', 'bob', 'mike']) Thanks, -thomas --~--~-~--~~~---~--~~ You received this

[sqlalchemy] Check if an item exists in a relation

2009-10-29 Thread Sergey V.
Hi all, I must be missing something obvious here... Let's suppose I have the following class: class User(Base): # addresses = relation(Address, backref=user) and I have a number which may be an ID of an Address object. How do I check if the number is an ID of one of Addresses of

[sqlalchemy] Re: Check if an item exists in a relation

2009-10-29 Thread Conor
Sergey V. wrote: Hi all, I must be missing something obvious here... Let's suppose I have the following class: class User(Base): # addresses = relation(Address, backref=user) and I have a number which may be an ID of an Address object. How do I check if the number is an

[sqlalchemy] Re: merge without merging related objects

2009-10-29 Thread Tvrtko
Now on 0.4.8. And it is just not working. My copy method is flawed. Don't use it. The innards of sqlalchemy are just too complicated to mess around with. As for the cascade option. It also doesn't work. I have the following: mapper(History, history_table, properties = dict( user =

[sqlalchemy] Re: merge without merging related objects

2009-10-29 Thread Michael Bayer
On Oct 29, 2009, at 7:22 PM, Tvrtko wrote: Now on 0.4.8. And it is just not working. My copy method is flawed. Don't use it. The innards of sqlalchemy are just too complicated to mess around with. As for the cascade option. It also doesn't work. I have the following: mapper(History,

[sqlalchemy] Re: Check if an item exists in a relation

2009-10-29 Thread Sergey V.
Some assumptions: 1. SA-mapped object means the user object in the example 2. property name means addresses in the example 3. The function shouldn't assume that you want an Address object 4. The ID attribute is known ahead of time (e.g. its always id). If not, your function will need

[sqlalchemy] Re: Check if an item exists in a relation

2009-10-29 Thread Sergey V.
Ahh... I missed the relation.any() part of your example - with it the code should behave exactly as I need. I think. I need to give it a try. Thanks! On Oct 30, 9:53 am, Sergey V. sergey.volob...@gmail.com wrote: Some assumptions: 1. SA-mapped object means the user object in the example

[sqlalchemy] Re: Check if an item exists in a relation

2009-10-29 Thread Conor
Sergey V. wrote: Some assumptions: 1. SA-mapped object means the user object in the example 2. property name means addresses in the example 3. The function shouldn't assume that you want an Address object 4. The ID attribute is known ahead of time (e.g. its always id). If not, your function