postgresqlpartioning
This is an old revision of the document!
Table of Contents
Partitioning
List
CREATE TABLE USERS_PART ( user_id serial, username VARCHAR(50), user_role VARCHAR(1), created_date DATE DEFAULT CURRENT_DATE, last_updated_ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP ) PARTITION BY LIST (user_role); -- Inserts would currently fail as we haven't defined any partitions for this table CREATE TABLE USERS_PART_A PARTITION OF USERS_PART FOR VALUES IN ('A'); -- Inserts will now only work with a user_role of A
Range
CREATE TABLE USERS_PART ( user_id serial, username varchar(50), user_role varchar(1), created_date DATE DEFAULT CURRENT_DATE, last_updated_ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP ) PARTITION BY RANGE (created_date); -- Inserts would currently fail as we haven't defined any partitions for this table CREATE TABLE USERS_PART_2021 PARTITION OF USERS_PART FOR VALUES FROM ('2021-01-01') TO ('2021-12-31'); -- Inserts will now only work when the created date is in 2021
postgresqlpartioning.1627319804.txt.gz · Last modified: 2025/03/08 22:23 (external edit)