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 293 indexed concepts. Below is a complete table-by-table outline of this topic, spanning foundational concepts through advanced details.
Table 1: Core Data Types
| 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. |