Search⌘ K
AI Features

Sequences

Explore how to use sequences in PostgreSQL to generate unique numeric identifiers automatically. Learn the creation of sequences with customizable parameters, how to retrieve sequence values using NEXTVAL and CURRVAL functions, and the role of sequences in columns defined with the SERIAL data type.

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 ...