Sequences
Learn about using sequences in the PostgreSQL database.
What are sequences?
In PostgreSQL, sequences are used to generate unique numeric identifiers for rows in a database table. This is useful when a primary key is needed, but the specific value of the key is not essential.
The CREATE SEQUENCE
statement
Sequences can be created using the CREATE SEQUENCE
statement and accessed using the CURRVAL()
and NEXTVAL()
functions. The start value, increment amount, maximum and minimum values, and whether the sequence cycles can all be set during creation.
Get hands-on with 1400+ tech skills courses.