sequence_next()

Advance the sequence to its next value and return that value.

sequence_reset()

Reset the sequence to its initial state or the specified value.

function
sequence_next()
std::sequence_next(seq: schema::ScalarType) -> int64

Advance the sequence to its next value and return that value.

Sequence advancement is done atomically, each concurrent session and transaction will receive a distinct sequence value.

Copy
db> 
SELECT sequence_next(INTROSPECT MySequence);
{11}
function
sequence_reset()
std::sequence_reset(seq: schema::ScalarType) -> int64std::sequence_reset( seq: schema::ScalarType, val: int64) -> int64

Reset the sequence to its initial state or the specified value.

The single-parameter form resets the sequence to its initial state, where the next sequence_next() call will return the first value in sequence. The two-parameters form allows changing the last returned value of the sequence.

Copy
db> 
SELECT sequence_reset(INTROSPECT MySequence);
{1}
Copy
db> 
SELECT sequence_next(INTROSPECT MySequence);
{1}
Copy
db> 
SELECT sequence_reset(INTROSPECT MySequence, 22);
{22}
Copy
db> 
SELECT sequence_next(INTROSPECT MySequence);
{23}

The sequence to be operated on by the functions above is specified by a schema::ScalarType object. If the sequence argument is known ahead of time and does not change, the recommended way to pass it is to use the INTROSPECT operator:

Copy
SELECT sequence_next(INTROSPECT MySequenceType);
# or
SELECT sequence_next(INTROSPECT TYPEOF MyObj.seq_prop);

This style will ensure that a reference to a sequence type from an expression is tracked properly to ensure schema referential integrity.

If, on the other hand, the operated sequence type is determined at run time via a query argument, it must be queried from the schema::ScalarType set directly like so:

Copy
WITH
  SeqType := (
    SELECT schema::ScalarType
    FILTER .name = <str>$seq_type_name
  )
SELECT
  sequence_next(SeqType);

Caution

To work efficiently in high concurrency without lock contention, a sequence_next() operation is never rolled back even if the containing transaction is aborted. This may result in gaps in the generated sequence. Likewise, sequence_reset() is not undone if the transaction is rolled back.

Light
Dark
System