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