如何使用OpenERP在Postgresql中获取最后一个插入的id
作者:互联网
我有一个插入查询,我想在OpenERP中获取最后一个插入的id.这是代码:
query = "INSERT INTO foo SELECT * FROM bar"
cr.execute(query) # cr => cursor
如何获取最后插入的ID?插入是空的时候发生了什么?
解决方法:
INSERT INTO table [ ( column [, ...] ) ]
{ DEFAULT VALUES | VALUES ( { expression | DEFAULT } [, ...] ) [, ...] | query }
[ RETURNING * | output_expression [ AS output_name ] [, ...] ]
Insert a single row into table distributors, returning the sequence number generated by the DEFAULT clause:
INSERT INTO distributors (did, dname) VALUES (DEFAULT, 'XYZ Widgets')
RETURNING did;
标签:python,openerp,postgresql 来源: https://codeday.me/bug/20190723/1516260.html