PARTITION BY (Table Partitioning)
PARTITION BY (Table Partitioning) is a SQL statement in the PostgreSQL Specific category. Divides a large table into smaller partitions for better query performance and easier maintenance. The syntax is CREATE TABLE table (...) PARTITION BY RANGE/LIST/HASH (column);. It returns partitioned table. A typical example: CREATE TABLE orders ( id INT, order_date DATE, amount DECIMAL ) PARTITION BY RANGE (order_date); -- Create partitions: CREATE TABLE orders_2024 PARTITION OF orders FOR VALUES FROM ('2024-01-01') TO ('2025-01-01'); CREATE TABLE orders_2025 PARTITION OF orders FOR VALUES FROM ('2025-01-01') TO ('2026-01-01'); -- Queries on orders automatically scan only relevant partitions A close relative is SERIAL, which postgreSQL auto-increment type. Creates an INTEGER column with a sequence. Equivalent to AUTO_INCREMENT in MySQL. A close relative is RETURNING, which postgreSQL extension that returns values from INSERT/UPDATE/DELETE statements (like OUTPUT in SQL Server). A close relative is ARRAY, which postgreSQL supports array columns and array operations. Can be multi-dimensional.