postgresqlpartioning
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| postgresqlpartioning [2021/07/26 17:05] – [List] z0hpvk | postgresqlpartioning [2025/03/08 22:24] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 9: | Line 9: | ||
| | | ||
| | | ||
| - | ) PARTITION BY LIST(user_role); | + | ) PARTITION BY LIST (user_role); |
| -- Inserts would currently fail as we haven' | -- Inserts would currently fail as we haven' | ||
| Line 19: | Line 19: | ||
| -- Inserts will now only work with a user_role of A | -- Inserts will now only work with a user_role of A | ||
| </ | </ | ||
| + | |||
| + | ===== Range ===== | ||
| + | <code SQL> | ||
| + | CREATE TABLE USERS_PART ( | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | ) PARTITION BY RANGE (created_date); | ||
| + | |||
| + | -- Inserts would currently fail as we haven' | ||
| + | |||
| + | CREATE TABLE USERS_PART_2021 | ||
| + | PARTITION OF USERS_PART | ||
| + | FOR VALUES FROM (' | ||
| + | |||
| + | -- Inserts will now only work when the created date is in 2021 | ||
| + | </ | ||
| + | |||
| + | ===== Default ===== | ||
| + | |||
| + | From Postgres 11 it is possible to create a default partition. \\ | ||
| + | <code SQL> | ||
| + | CREATE TABLE USERS_PART_DF PARTITION OF USERS_PART DEFAULT; | ||
| + | </ | ||
| + | |||
| + | ===== Select / Insert ===== | ||
| + | |||
| + | It is possible to show which partitioned table your select or insert query has used. \\ | ||
| + | <code SQL> | ||
| + | SELECT tableoid, tableoid:: | ||
| + | WHERE user_role = ' | ||
| + | </ | ||
| + | |||
| + | <code SQL> | ||
| + | INSERT INTO users_part (username, user_role) | ||
| + | VALUES (' | ||
| + | RETURNING tableoid:: | ||
| + | </ | ||
| + | |||
| + | ===== Example ===== | ||
| + | [[PGPartitionExample| Partitioning Example]]\\ | ||
| + | |||
postgresqlpartioning.1627319152.txt.gz · Last modified: (external edit)
