Alex Brasetvik wrote: > On 12/20/09 13:31 , Igor Katson wrote: > >> I want to increment a column by 1 with >> >> UPDATE table SET column = column + 1 WHERE id = %(id)s, > > This is covered here: > http://www.sqlalchemy.org/docs/06/sqlexpression.html > >> however, when writing "instance.column += 1" in python, it translates it to >> >> UPDATE table SET column = <OLD_VALUE> + 1 > > That's because instance.column returns the integer value. If you do > "table.c.column + 1", however, that will return a _BinaryExpression. > > So, what you want, is something like > > table.update(where_clause, dict(column=table.c.column + 1) > > Hope this helps. > Thanks, Alex, your variant seems really the same as mine. I have found a way to do that though simpler, this is:
instance.column = table.c.column + 1 Works like a charm, though instance.column becomes a binary expression and you can not access the real value until you do session.flush -- 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.
