一个分区表
是一种特殊的表,它已使用声明式分区提供的其中一种方法划分为多个分区。无法将数据插入分区表本身;所有插入操作都必须能够路由到其分区之一。
分区表
自PostgreSQL 10添加声明式分区以来一直存在。
示例
创建来自PostgreSQL 分区文档的示例表
postgres=# CREATE TABLE measurement ( city_id INT NOT NULL, logdate DATE NOT NULL, peaktemp INT, unitsales INT ) PARTITION BY RANGE (logdate); CREATE TABLE postgres=# \dt List of relations Schema | Name | Type | Owner --------+-------------+-------------------+---------- public | measurement | partitioned table | postgres (1 row) postgres=# \d measurement Partitioned table "public.measurement" Column | Type | Collation | Nullable | Default -----------+---------+-----------+----------+--------- city_id | integer | | not null | logdate | date | | not null | peaktemp | integer | | | unitsales | integer | | | Partition key: RANGE (logdate) Number of partitions: 0
由于不存在分区,因此无法将数据插入此表
postgres=# INSERT INTO measurement VALUES(1, CURRENT_DATE, 25, 3); ERROR: no partition of relation "measurement" found for row DETAIL: Partition key of the failing row contains (logdate) = (2021-11-08).
参考
- PostgreSQL 文档: 声明式分区