lastval()

Synopsis

Use the lastval() function to return the value returned from the last call to nextval(), for any sequence, in the current session.

Semantics

  • An error is raised if nextval() has not been called in the current session.

Examples

Create two sequences and call nextval() for each of them.

yugabyte=# CREATE SEQUENCE s1;
CREATE SEQUENCE
yugabyte=# CREATE SEQUENCE s2 START -100 MINVALUE -100;
CREATE SEQUENCE
yugabyte=# SELECT nextval('s1');
 nextval
---------
       1
(1 row)
yugabyte=# SELECT nextval('s2');
 nextval
---------
    -100
(1 row)

Call lastval().

yugabyte=# SELECT lastval()
 lastval
---------
    -100
(1 row)

See also