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.

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

  1. nextval

  1. 1

(1 row)

  1. yugabyte=# SELECT nextval('s2');

  1. nextval

  1. -100

(1 row)

Call lastval().

  1. yugabyte=# SELECT lastval()

  1. lastval

  1. -100

(1 row)

See also

CREATE SEQUENCEDROP SEQUENCEcurrval()nextval()