Appearance
sys.sequence
This view captures information about the sequences that exist in the system. See Generating Values with Sequences.
Column Name | Data Type | Description |
---|---|---|
database_id | bigint | The unique ID for the database. |
schema_id | bigint | The unique schema ID for the sequence. |
sequence_id | bigint | The unique ID for the sequence. |
name | name | The user-defined name of the sequence. |
fullname | text | The user-defined name of the sequence, pre-pended with the schema name. |
start_value | bigint | The current starting value for the sequence. |
last_value | bigint | The last value of the sequence, as calculated below. |
min_value | bigint | The minimum value that the sequence can generate. |
max_value | bigint | The maximum value that the sequence can generate. |
is_temp | boolean | Whether the sequence was created as a temporary sequence (f =persistent; t =temporary). |
creation_time | timestamptz | When the sequence was created. |
About last_value
The value in the last_value
column is derived using the following formula:
sql
last_value = (NEXTVAL('my_seq_name') - sys.worker_id()) / 1024
Where:
NEXTVAL
returns the next number from the sequence.sys.worker_id()
returns the compute node ID.
Example
premdb=# create sequence matchid start 50000;
CREATE SEQUENCE
premdb=> select * from sys.sequence;
database_id | schema_id | sequence_id | owner_id | name | fullname | start_value | last_value | min_value | max_value | is_temp | creation_time
-------------+-----------+-------------+----------+---------+----------------+-------------+------------+----------------------+---------------------+---------+-------------------------------
16400 | 24638 | 25507 | 25048 | matchid | premdb.matchid | 49 | 49 | -9223372036854775807 | 9223372036854775807 | f | 2022-09-13 14:05:13.911498-07
(1 row)
premdb=> select nextval('matchid');
nextval
---------
51199
(1 row)