BIGSERIAL (8-byte auto-increment pseudo-type)
Last updated: 2026-11-04
BIGSERIAL (8-byte auto-increment pseudo-type)
BIGSERIAL stands to SERIAL as BIGINT stands to INTEGER: it is a pseudo-type made of a BIGINT column plus an auto-increment sequence, covering -9223372036854775808 to 9223372036854775807. It is the right choice once a table is expected to exceed 2.1 billion rows or when primary keys must be merged across databases. Like SERIAL it is not an independent type; the storage type underneath is BIGINT.
| Kind | type |
|---|---|
| Example Language | SQL |
📝 Syntax
BIGSERIAL | SERIAL8
-- equivalent to:
-- id bigint NOT NULL DEFAULT nextval('t_bigserial_id_seq')
-- plus an automatically created sequence named t_bigserial_id_seq
Returns:A BIGSERIAL column is physically a BIGINT whose values are handed out by the backing sequence, which starts at 1 and steps by 1.
▶ 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 | bigint | nextval('t_bigserial_id_seq'::regclass)
2 | Bob | bigint | nextval('t_bigserial_id_seq'::regclass)
📌 Key Points
- In information_schema the column's data_type is bigint and its column_default is nextval('t_bigserial_id_seq'::regclass).
- The sequence is owned by the column and is dropped together with the table; it can be widened on its own with ALTER SEQUENCE ... AS bigint.
- As with SERIAL, inserting a hand-picked id does not advance the sequence, so the next insert continues from the sequence's current value.
💡 Related Cases
More case studies coming soon.
📚 Related Reference
❓ FAQ
QDo BIGSERIAL IDs keep increasing?
AYes. The sequence advances monotonically and never wraps, and deleted rows do not free their IDs for reuse. If you need gap-free consecutive numbering, use IDENTITY or maintain the counter yourself.
QCan a BIGSERIAL column be converted to IDENTITY?
ANot with a plain ALTER. The workable path is to add a GENERATED ALWAYS AS IDENTITY column, sync the sequence value over, then drop the old column, or to migrate by rebuilding the table.