开发者

After doing a SQLAlchemy update(), is there a way to get the changed values?

After calling update(), I know that the return value has a .rowcount attribute that will reveal how many rows were changed. Is there a way to get the开发者_如何学运维 actual new values that they were changed to?

For example, if I do the SQLAlchemy equivalent of:

UPDATE t SET x=x+1 WHERE y=z

...is there a way to get the new value for x? Or do I have to do a SELECT?


The ResultProxy has two methods, last_updated_params() which returns a dictionary of every bind parameter value sent with the statement execution, as well as a collection postfetch_cols(), a list of columns for which an inline SQL expression was embedded in the UPDATE (for which you'd have to post-SELECT the values). These collections are only populated for single-statement executions, not "executemany" calls which pass multiple sets of parameters along.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜