Advance the sequence to its next value and return that value. | |
Reset the sequence to its initial state or the specified value. |
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.
db>
SELECT sequence_next(INTROSPECT MySequence);
{11}
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.
db>
SELECT sequence_reset(INTROSPECT MySequence);
{1}
db>
SELECT sequence_next(INTROSPECT MySequence);
{1}
db>
SELECT sequence_reset(INTROSPECT MySequence, 22);
{22}
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:
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:
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.