currval()
Synopsis
Use the currval( sequence_name )
function to return the last value returned by the nextval( sequence_name )
function for the specified sequence in the current session.
Semantics
_sequencename
Specify the name of the sequence.
- An error is raised if
nextval( sequence_name )
has not been called for the specified sequence in the current session.
Examples
Create a sequence
yugabyte=# CREATE SEQUENCE s;
CREATE SEQUENCE
Call nextval()
.
yugabyte=# SELECT nextval('s');
nextval
nextval
1
(1 row)
yugabyte=# SELECT currval('s');
currval
currval
1
(1 row)
Call currval()
before nextval()
is called.
yugabyte=# CREATE SEQUENCE s2;
CREATE SEQUENCE
SELECT currval('s2');
ERROR: currval of sequence "s2" is not yet defined in this session
See also
当前内容版权归 YugabyteDB 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 YugabyteDB .