Data Type Picker

PostgreSQL

Categories

PostgresGUI

Special

Prefer GENERATED ALWAYS AS IDENTITY over serial

GENERATED ALWAYS AS IDENTITY4 or 8 bytes (integer/bigint)Recommended

Auto-incrementing primary keys. SQL-standard replacement for serial.


Range

depends on underlying type

Performance

Same as serial internally. Stricter — prevents manual ID insertion by default.

Comparison

identity vs serial: identity is SQL-standard, prevents accidental manual inserts, and works correctly with table inheritance. serial is PostgreSQL-specific and creates a separate sequence with looser ownership. Always prefer identity.

SQL Example
CREATE TABLE orders (
  id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
  total numeric(10,2) NOT NULL
);
PostgreSQL Special Types — identity, serial, enum, inet, tsvector | PostgresGUI