Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Create Table with SERIAL

Check name: CreateTableSerialCheck

Lock type:

Bad

SERIAL / BIGSERIAL / SMALLSERIAL are PostgreSQL pseudo-types (not standard SQL). They create separately-owned sequence objects, which can complicate permissions, dump/restore, and replication workflows.

CREATE TABLE events (id BIGSERIAL PRIMARY KEY);
CREATE TABLE users (id SERIAL PRIMARY KEY);
CREATE TABLE users (external_id SERIAL NOT NULL UNIQUE, id BIGINT PRIMARY KEY);

Good

Prefer SQL-standard identity columns:

CREATE TABLE events (
  id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY
);

CREATE TABLE users (
  id INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY
);

Key insight: For new schemas on PostgreSQL 10+, identity columns avoid SERIAL pseudo-type drawbacks while keeping auto-increment semantics.