您的位置:首页 > 其它

如何用简便的方法获取刚插入的数据的id

u011465574 2013-11-07 17:12 120 查看
Here is a small patch that implements a function lastval() that
works just like currval() except that it give the current
value of the last sequence used by nextval().

Using this function one can do:

# CREATE TABLE abc (a serial, b int);
CREATE TABLE

# SELECT lastval();
ERROR:  nextval have not been used in the current session

# INSERT INTO abc(b) VALUES (42);
INSERT 0 1

# SELECT lastval();
lastval
---------
1
标签: