In PostgreSQL, the currval()
function returns the value most recently returned by nextval()
for the specified sequence in the current session.
The currval()
function is very similar to the lastval()
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. The currval()
on the other hand, only reports on the specified sequence.