Michael Bayer wrote: > On Dec 22, 2009, at 2:51 PM, Igor Katson wrote: > > >> I am concerned about the problem of the orm framework using SELECT's a >> lot, which can be not used in many cases, when dealing with Postgres >> after INSERTs or UPDATEs. >> >> When using postgresql, I want sqlalchemy, when updating the instance >> parameters not to issue additional SELECTS after Session.flush() or >> Session.commit(), but to be able to use INSERT/UPDATE...RETURNING, which >> will update the values based on the database data. >> >> As far as I see, there is no such functionality in the mapper or >> Session, and I want to extend it for personal use. >> >> Could you please guide me in the right direction, how to make that? >> > > 0.5 supports this using the "postgres_returning" argument to update() and > insert(), but the ORM doesn't make use of it. in 0.6, the feature has been > generalized using the returning() method on insert() and update(), and the > ORM will use it to fetch new primary key identifiers. > > It does not take effect within the ORM for inline SQL other than primary key > identifiers, but you can use an insert() with returning() manually to achieve > that effect. > Why not, Michael? Is it hard to implement this? This seems to be pretty useful and performance-improving, reducing the amount of selects needed when coding unaware of object expiry.
P.S. And in SQLAlchemy 0.5, what's the most orm-like way to do solve this? In my code, it looks like this now, cause I didn't find an easier (less lines + less sql-like code) way to do it. columns = ','.join([str(col) for col in obj_table.c]) query = '''UPDATE %(table)s SET col = col + %(value)s WHERE id = %(id)s RETURNING %(columns)s''' % { 'id': id, 'columns': columns, 'table': obj_table, 'value': value } obj = meta.Session.query(Obj).from_statement(query).first() Thanks, Igor Katson -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.