SERIAL (auto-increment pseudo-type)
Last updated: 2026-11-04
SERIAL (auto-increment pseudo-type)
SERIAL is not a real storage type but a PostgreSQL pseudo-type: writing SERIAL is shorthand for creating an INTEGER column, a standalone SEQUENCE and a DEFAULT nextval(...) clause pointing at that sequence. When the column is omitted on insert, the sequence hands out the next value. The construct predates standard identity columns, so SQL-standard IDENTITY is usually the better choice today, yet SERIAL remains the most common form in existing code.
| Kind | type |
|---|---|
| Example Language | SQL |
📝 Syntax
SERIAL | SERIAL4
-- equivalent to:
-- id integer NOT NULL DEFAULT nextval('t_serial_id_seq')
-- plus an automatically created sequence named t_serial_id_seq
Returns:A SERIAL column is physically an INTEGER whose values come from the backing sequence, which starts at 1 and increments by 1 unless changed with ALTER SEQUENCE.
▶ Example
Runs real PostgreSQL 18 right in your browser (PGlite WASM, nothing to install). Press ▶ Run and the result appears in the panel below.
Output:
id | name | data_type | column_default
----+-------+-----------+--------------------------------------
1 | Alice | integer | nextval('t_serial_id_seq'::regclass)
2 | Bob | integer | nextval('t_serial_id_seq'::regclass)
📌 Key Points
- SERIAL is a pseudo-type: in information_schema the column's data_type is integer and its column_default is nextval('t_serial_id_seq'::regclass).
- The sequence is owned by the column, so it is dropped together with the table; TRUNCATE leaves it alone, and TRUNCATE ... RESTART IDENTITY is what resets it.
- Compared with IDENTITY: SERIAL still accepts manually supplied values (and the sequence does not follow along), while GENERATED ALWAYS AS IDENTITY rejects them.