首页 > 解决方案 > 如何在 PostgreSQL 中使用分区内分区(多级分区或分区分区)

问题描述

如何在 PostgreSQL 中的分区内使用分区我想在 PostgreSQL 中进行多级分区就像在第一个表中的列 id 和第二个分区表中的列日期一样,这将是三层层次结构

标签: postgresqldatabase-partitioning

解决方案


本文通过示例 https://joaodlf.com/postgresql-10-partitions-of-partitions.html对此进行了很好的解释

CREATE TABLE dt_totals (
    dt_total date NOT NULL,
    geo varchar(2) not null,
    impressions integer DEFAULT 0 NOT NULL,
    sales integer DEFAULT 0 NOT NULL
)
PARTITION BY RANGE (dt_total);
CREATE TABLE dt_totals_201801
PARTITION OF dt_totals
FOR VALUES FROM ('2018-01-01') TO ('2018-01-31');
CREATE TABLE dt_totals_201801
PARTITION OF dt_totals
FOR VALUES FROM ('2018-01-01') TO ('2018-01-31')
PARTITION BY LIST (geo);
CREATE TABLE dt_totals_UK_201801 PARTITION OF dt_totals_201801 FOR VALUES IN ('UK');
CREATE TABLE dt_totals_US_201801 PARTITION OF dt_totals_201801 FOR VALUES IN ('US');
CREATE TABLE dt_totals_AU_201801 PARTITION OF dt_totals_201801 FOR VALUES IN ('AU');


推荐阅读