一个分区表
是一种特殊的表,它已使用 声明式分区 提供的方法之一将其划分为多个分区。无法直接向分区表本身插入数据;所有插入操作都必须能够路由到其分区之一。
分区表
自 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 文档: 声明式分区