IT lexicon › Database › Sequence

Sequence

Database På svenska → Updated: 2026-07-29

A database object whose only job is to hand out the next number in order. It sits behind SERIAL and IDENTITY and is the normal way to generate primary keys.

The property that surprises most people is that gaps are entirely normal. A sequence is deliberately non-transactional: fetch a value and roll back the transaction and it isn't returned, because otherwise every insert would have to serialize and performance would collapse. Per-session caching and restarts create further jumps. So the numbers are unique and increasing — not contiguous. A common mistake is building invoice numbers or other counting series that require an unbroken run directly on a sequence; that needs its own table with locking. IDENTITY is the SQL standard syntax and is recommended over SERIAL in PostgreSQL.

← Back to the lexicon