创建基于时间字段的分区表后,创建主键(非时间字段的)时报错, ERROR: insufficient columns in UNIQUE constraint definition DETAIL: UNIQUE constraint on table "test_range" lacks column "date" which is part of the partition key.
请问:
在分区表中如何创建时间为分区键,但是时间字段不做为主键一部分的表结构?
问题:唯一约束不包含分区键报错,很明白
示例:
create table test_unique(x int, y int unique) partition by range(x);
ERROR: insufficient columns in UNIQUE constraint definition
DETAIL: UNIQUE constraint on table "test_unique" lacks column "x" which is part of the partition key.
create table test_unique(x int primary key, y int) partition by range(x);
\d+ test_unique
Table "public.test_unique"
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description |
---|---|---|---|---|---|---|---|
x | integer | not null | plain | ||||
y | integer | plain |
Partition key: RANGE (x)
Indexes:
"test_unique_pkey" PRIMARY KEY, btree (x)
Number of partitions: 0
收起