Skip to content
gohacks.dev
Databases

PostgreSQL Data Types

A reference of PostgreSQL data types with storage and the notes that matter: integers and identity, numeric, text versus varchar, timestamptz, uuid, jsonb, network types, arrays, ranges and extensions.

Free · No sign-up · Your inputs stay in your browser

Reference

PostgreSQL data types

TypeStorageRange and notes
smallint / integer / bigint2 / 4 / 8 bytes±32,767; ±2.1 × 10^9; ±9.2 × 10^18. No unsigned types.
generated always as identity-The modern auto-increment, replacing serial and bigserial.
numeric(p,s)variableExact, up to 131,072 digits before the point. For money.
real / double precision4 / 8 bytesApproximate floating point.
boolean1 bytetrue, false or null.
textvariableUnlimited length, and no slower than varchar. The idiomatic string type.
varchar(n)variabletext with a length check; changing n later rewrites nothing since 9.2.
char(n)variableBlank-padded; rarely what you want.
byteavariableBinary data.
uuid16 bytesNative type; gen_random_uuid() is built in since 13, uuidv7() since 18.
date4 bytes4713 BC to 5874897 AD.
timestamp8 bytesWithout time zone: a wall-clock time with no zone attached.
timestamptz8 bytesWith time zone: stored as UTC, shown in the session's TimeZone. Use this for events.
time / timetz8 / 12 bytesTime of day.
interval16 bytesA duration: '2 days 3 hours'.
jsonvariableStored as text, keeps formatting and duplicate keys.
jsonbvariableBinary, indexable with GIN, deduplicated keys. Use jsonb unless you need the original text.
inet / cidr7 or 19 bytesIPv4 and IPv6 addresses and networks, with operators like << (is contained by).
macaddr6 bytes
integer[] / text[]variableArrays of any type, indexable with GIN.
int4range / tstzrangevariableRanges, with exclusion constraints to forbid overlapping bookings.
tsvector / tsqueryvariableFull-text search.
enum (CREATE TYPE)4 bytesValues can be added but not removed or reordered easily.
money8 bytesLocale-dependent formatting; numeric is the safer choice.
point / polygon (PostGIS geometry)variableBuilt-in geometric types; PostGIS adds geography with real-world units.
vector(n) (pgvector)4 × n + 8 bytesExtension for embeddings with HNSW and IVFFlat indexes.

From the PostgreSQL documentation, current through version 18. The two choices that cause the most pain later: timestamp where timestamptz was meant, and json where jsonb was meant. Both are easy to get right on day one and expensive to migrate.

Two common mistakes

timestamp without time zone stores a wall-clock time and is the wrong choice for events; timestamptz stores an absolute instant and displays it in the session zone. json keeps text as written and cannot be indexed efficiently; jsonb is parsed, indexable with GIN and almost always what you want. The data types chapter covers every type.

text is fine

In PostgreSQL text and varchar have the same performance; varchar(n) only adds a length check. Use text with a CHECK constraint when a limit is a business rule.

Share

Frequently asked questions

What is the PostgreSQL equivalent of AUTO_INCREMENT?
An identity column: id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY. serial and bigserial still work but are older.
Does PostgreSQL have unsigned integers?
No. Use the next larger type, or a CHECK (value >= 0) constraint.
Is what I paste sent anywhere?
No. The tool runs entirely in your browser with JavaScript. Nothing you type or paste is sent to our server or stored.

Keep planning

Similar tools