Hi,
when I started using code like
obj.column = obj.column + 1,
which I had to make through raw sql (because in SQL e.g. "update...set
column = 400 + 1" is not equal to "update...set column = column + 1",
when many threads do this concurrently), I faced a problem, that to
update the value and get the result I should make 3 queries.
e.g.
def action(self, id):
obj = Session.query(Obj).get(id)
obj.column = obj_table.c.column + 1
Session.flush()
new_value = obj.column
# here the mapped object is fully updated after 3 queries
When using PostgreSQL I can make it all in 1 update query, e.g
def action(self, id):
obj = Session.query(Obj).from_sql('''
UPDATE obj_table SET column = column + 1
WHERE id = %s
RETURNING *''' % id
# here the object is initialized and fully updated after 1 query
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?
Best regards,
Igor Katson.
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en.