lastval()
This page documents the preview version (v2.23). Preview includes features under active development and is for development and testing only. For production, use the stable version (v2024.1). To learn more, see Versioning.
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)