PostgreSQL (version 18, released September 2025) is an advanced open-source relational database management system known for its robustness, extensibility, and SQL standards compliance. Originally developed at UC Berkeley in the 1980s, it supports complex queries, ACID transactions, and a wide array of data types including JSON, arrays, geospatial data, and vectors. PostgreSQL 18 introduces asynchronous I/O, UUIDv7, virtual generated columns, and temporal constraints β continuing its position as the most feature-rich open-source database. The key to mastering PostgreSQL lies in understanding its query planner β learning to read EXPLAIN ANALYZE output transforms guesswork into precision when optimizing performance.
What This Cheat Sheet Covers
This topic spans 30 focused tables and 296 indexed concepts, 212 flashcards, 10 practice tests with 381 questions. Below is a complete table-by-table outline of this topic, spanning foundational concepts through advanced details.
A jump-to index of every table row in this cheat sheet.
An interactive map of every table and concept in this topic.
Table 1: Core Data Types
Choosing the right column type is the first design decision in any schema, and PostgreSQL gives you a richer palette than most databases β exact decimals for money, native UUIDs, JSONB for semi-structured data, arrays, and ranges all sit alongside the usual integers and strings. The notes here flag the modern defaults that experienced users reach for: TIMESTAMPTZ over TIMESTAMP, JSONB over JSON, IDENTITY over the legacy SERIAL.
| Type | Example | Description | |
|---|---|---|---|
user_id INTEGER | β’ 4-byte signed integer storing values from -2,147,483,648 to 2,147,483,647 β’ most common choice for IDs and counters. | ||
transaction_id BIGINT | β’ 8-byte signed integer for very large numbers β’ essential for high-volume systems where INTEGER would overflow. | ||
age SMALLINT | 2-byte signed integer (-32,768 to 32,767) β use for small-range values to save storage. | ||
price NUMERIC(10,2) | β’ Exact arbitrary-precision decimal β’ use for financial calculations where floating-point errors are unacceptable. | ||
measurement REAL | β’ 4-byte floating-point with ~6 decimal digits precision β’ faster than NUMERIC but inexact. | ||
latitude DOUBLE PRECISION | β’ 8-byte floating-point with ~15 decimal digits precision β’ standard for scientific and geospatial calculations. | ||
description TEXT | β’ Unlimited-length string β’ identical performance to VARCHAR but without length limit β preferred unless you need length validation. | ||
name VARCHAR(100) | β’ Variable-length string with optional maximum length β’ no performance advantage over TEXT β length is only a constraint. | ||
country_code CHAR(2) | β’ Fixed-length string padded with spaces β’ rarely needed β only use for truly fixed-width data like codes. | ||
is_active BOOLEAN | β’ Stores TRUE, FALSE, or NULL β’ accepts various input formats like 't', 'yes', '1' for TRUE. | ||
birth_date DATE | Calendar date without time β range from 4713 BC to 5874897 AD. | ||
created_at TIMESTAMP | β’ Date and time without timezone β’ stores the date and time exactly as written, with no timezone context, so the same value can mean different real moments depending on which zone it's read in. | ||
updated_at TIMESTAMPTZ | β’ Date and time with timezone β’ converts to UTC internally β always prefer this over TIMESTAMP for consistency. | ||
duration INTERVAL | β’ Time span like '3 days' or '2 hours 30 minutes'β’ supports arithmetic with dates and timestamps. | ||
session_id UUID DEFAULT gen_random_uuid() | β’ 128-bit universally unique identifier β’ use uuidv7() (PG18) for time-sortable IDs or gen_random_uuid() for random UUIDv4. | ||
config JSONB | β’ Binary JSON with full indexing support β’ slightly slower to insert but much faster to query β the standard choice over JSON. | ||
metadata JSON | β’ Stores JSON as text, validates syntax β’ doesn't index efficiently β use JSONB instead. | ||
tags TEXT[] | β’ Variable-length multidimensional array of any type β’ use bracket notation [1] for access. | ||
file_data BYTEA | Binary data storage for images and files β stored as byte array with hex or escape encoding. | ||
id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY | β’ SQL-standard auto-incrementing column β’ replaces SERIAL β sequence is owned by the column and cannot be accidentally overridden. | ||
valid_period tstzrange | β’ Built-in range types for dates and timestamps β’ support overlap, contains, adjacent operators β essential for temporal data. | ||
id SERIAL PRIMARY KEY | β’ Auto-incrementing INTEGER via implicit sequence β’ use IDENTITY columns instead for new tables β SERIAL has ownership issues. |