SYSCS_UTIL.SYSCS_PEEK_AT_SEQUENCE system function

The SYSCS_UTIL.SYSCS_PEEK_AT_SEQUENCE function allows users to observe the instantaneous current value of a sequence generator without having to query the SYSSEQUENCES system table.

Querying the SYSSEQUENCES system table does not actually return the current value; it only returns an upper bound on that value, that is, the end of the chunk of sequence values which has been preallocated but not actually used. The SYSCS_UTIL.SYSCS_PEEK_AT_SEQUENCE function shows you the very next value which will be returned by a NEXT VALUE FOR clause. Users should never directly query the SYSSEQUENCES table, because that will cause sequence generator concurrency to slow drastically.

Syntax

BIGINT SYSCS_UTIL.SYSCS_PEEK_AT_SEQUENCE(IN SCHEMANAME VARCHAR(128),
IN SEQUENCENAME VARCHAR(128))

As with all system functions, schema and object name arguments are case-sensitive.

Execute privileges

By default, all users have execute privileges on this function.

Example

VALUES SYSCS_UTIL.SYSCS_PEEK_AT_SEQUENCE('APP', 'order_entry_id');
Related reference
CREATE SEQUENCE statement
DROP SEQUENCE statement
SYSSEQUENCES system table
derby.language.sequence.preallocator