【发布时间】:2022-01-13 02:49:02
【问题描述】:
我有以下example:
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')
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');
在我的环境中生成一个名为 level_part 的架构;
CREATE SCHEMA IF NOT EXISTS level_part
AUTHORIZATION postgres;
到目前为止一切顺利,我生成了主分区表:
CREATE TABLE IF NOT EXISTS level_part.dt_totals
(
dt_total date NOT NULL,
geo character varying(2) COLLATE pg_catalog."default" NOT NULL,
impressions integer NOT NULL DEFAULT 0,
sales integer NOT NULL DEFAULT 0
) PARTITION BY RANGE (dt_total);
ALTER TABLE IF EXISTS level_part.dt_totals
OWNER to postgres;
-- Partitions SQL
CREATE TABLE public.dt_totals_201801 PARTITION OF level_part.dt_totals
FOR VALUES FROM ('2018-01-01') TO ('2018-01-31')
PARTITION BY LIST (geo);
ALTER TABLE IF EXISTS public.dt_totals_201801
OWNER to postgres;
问题
- 为什么指向公共架构
- 是 pgadmin 错误吗?
当我尝试按如下方式生成分区时:
CREATE TABLE dt_totals_AU_201801 PARTITION OF level_part.dt_totals_201801 FOR VALUES IN ('AU');
我收到一个错误:
ERROR: relation "level_part.dt_totals_201801" does not exist
SQL state: 42P01
但如果我将架构更改为公开,我可以参考该表:
CREATE TABLE dt_totals_AU_201801 PARTITION OF public.dt_totals_201801 FOR VALUES IN ('AU');
为什么我只能引用公共架构中的表?
【问题讨论】:
-
好吧,您在架构
public中创建了表/分区dt_totals_201801- 为什么您希望它在架构level_part中? -
顺便说一句:您不应该以超级用户身份创建所有表。这是一个非常糟糕的主意
标签: postgresql database-design partitioning database-partitioning postgresql-12