如何在PostgreSQL中使用分区内的分区多级分区或分区的分区

问题描述

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

解决方法

本文通过示例很好地解释了这一点 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');