In PostgreSQL, the lastval()
function returns the value most recently returned by nextval()
 in the current session.
The lastval()
function is very similar to the currval()
function, except that lastval()
doesn’t require the name of a sequence like currval()
does. That’s because lastval()
doesn’t report on any particular sequence – it reports on the last time nextval()
was used in the current session, regardless of which sequence was used.