SQL Data Types Table

–click a type to copy it - sizes are for PostgreSQL
TypeCategorySize / Range
SMALLINTNumeric2 bytes, -32,768 to +32,767
INTEGERNumeric4 bytes, -2.1B to +2.1B
BIGINTNumeric8 bytes, -9.2Q to +9.2Q
DECIMAL(p,s)NumericVariable, exact precision - use for money
REALNumeric4 bytes, 6 decimal digits precision
DOUBLE PRECISIONNumeric8 bytes, 15 decimal digits precision
VARCHAR(n)TextVariable length, max n characters
TEXTTextVariable length, unlimited (PostgreSQL preference)
CHAR(n)TextFixed length, blank-padded
BOOLEANBoolean1 byte, true or false
DATEDate/Time4 bytes, calendar date only (no time)
TIMEDate/TimeTime of day only (no date)
TIMESTAMPDate/Time8 bytes, date and time (no timezone)
TIMESTAMPTZDate/Time8 bytes, date and time with timezone
UUIDOther16 bytes, universally unique identifier
JSONBOtherVariable, binary JSON - indexed and queryable
BYTEAOtherVariable, binary data (files, images)
SERIALOtherAuto-incrementing integer (4 bytes)
Types and sizes follow the PostgreSQL data type documentation. The three decisions that matter most: TEXT vs VARCHAR (PostgreSQL treats them identically - TEXT is the community preference because there is no performance penalty for unlimited length), DECIMAL vs REAL (DECIMAL for money, REAL for scientific data - floating-point cannot represent 0.1 exactly), and TIMESTAMP vs TIMESTAMPTZ (always use TIMESTAMPTZ in production; it stores UTC and converts on display). Bottom line: JSONB is the PostgreSQL superpower - it indexes and queries semi-structured data that would require a separate NoSQL database in other engines. SQL context: SQL joins table, GCD and LCM calculator, HTTP methods table, regex cheatsheet.

Choosing the right SQL data type is a one-time decision that affects storage, indexing, query performance and correctness forever - changing a column type on a million-row table requires a full table rewrite. This table covers the 18 most-used PostgreSQL types verbatim from the official documentation.

The three PostgreSQL community preferences that surprise newcomers: TEXT over VARCHAR (identical performance, no arbitrary limit), TIMESTAMPTZ over TIMESTAMP (always stores UTC, converts on display), and JSONB over JSON (binary format, indexed, queryable).

How to use

  1. Filter by type name or category - numeric, text, date, other - to find the type you need.
  2. Check the size column for storage planning: BIGINT is 8 bytes, TEXT is variable, UUID is fixed at 16 bytes.
  3. Click any type to copy the type name for a CREATE TABLE statement.

Frequently asked questions

What is the difference between VARCHAR(n) and TEXT?

In PostgreSQL they are functionally identical - both store variable-length text with no performance difference. VARCHAR(n) adds a length check, but the PostgreSQL community prefers TEXT because you can add a CHECK constraint (char_length(name) <= 255) that is easier to change later. Other databases (MySQL) treat these very differently.

Why should I use DECIMAL instead of REAL for money?

REAL and DOUBLE PRECISION are floating-point types that cannot represent decimal fractions exactly: 0.1 + 0.2 = 0.30000000000000004. DECIMAL uses exact decimal arithmetic, so 0.1 + 0.2 = 0.3. For any application that handles money, the difference between $10.00 and $10.000000000000002 is a real bug.

What is the difference between TIMESTAMP and TIMESTAMPTZ?

TIMESTAMP stores the literal date and time with no timezone information - 2026-01-01 12:00 means whatever timezone the reader assumes. TIMESTAMPTZ stores the same value but converts input to UTC and converts output to the session timezone - making it the only safe choice for applications with users in multiple timezones.

When should I use JSONB instead of separate columns?

Use JSONB when the data structure varies per row (product attributes with different fields) or when you need flexibility without schema migrations. Use separate columns when the fields are always present, need foreign key constraints, or require strict type enforcement. JSONB supports GIN indexing for fast queries on nested keys.

Related tools