分区表

使用声明式分区划分的表

分区表 是一种特殊的表,它使用 声明式分区 提供的方法之一将其划分为分区。无法直接向分区表本身插入数据;所有插入操作都必须能够路由到其某个分区。

分区表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).

分类

分区

另请参阅

声明式分区, pg_partitioned_table

反馈

提交任何关于 "分区表" 的评论、建议或更正,请在此处 提交.