postgres创建基于时间字段的分区表后,创建主键(非时间字段的)时报错?

创建基于时间字段的分区表后,创建主键(非时间字段的)时报错, ERROR:  insufficient columns in UNIQUE constraint definition DETAIL:  UNIQUE constraint on table "test_range" lacks column "date" which is part of the partition key.请问:在分区表中如何创建时间为分...显示全部

创建基于时间字段的分区表后,创建主键(非时间字段的)时报错, ERROR:  insufficient columns in UNIQUE constraint definition DETAIL:  UNIQUE constraint on table "test_range" lacks column "date" which is part of the partition key.

请问:
在分区表中如何创建时间为分区键,但是时间字段不做为主键一部分的表结构?

收起
参与5

返回y18511664518的回答

y18511664518y18511664518技术总监长城超云

问题:唯一约束不包含分区键报错,很明白
示例:
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"
ColumnTypeCollationNullableDefaultStorageStats targetDescription
xinteger not null plain
yinteger plain

Partition key: RANGE (x)
Indexes:

"test_unique_pkey" PRIMARY KEY, btree (x)

Number of partitions: 0

金融其它 · 2019-08-02
浏览3978
  • 这个测试之前做过,也知道分区键必须为主键一部分,但实际场景是时间作为分区键,时间作为主键不符合业务,原主键+时间有不能用上时间索引,去检索,在insert量非常大场景,多个主键字段会影响insert性能,此问题的目的的是否有方案,实现时间不作为主键一部分而且能按时间分区?
    2019-08-05

回答者

y18511664518
技术总监长城超云
擅长领域: 数据库存储关系型数据库

y18511664518 最近回答过的问题

回答状态

  • 发布时间:2019-08-02
  • 关注会员:2 人
  • 回答浏览:3978
  • X社区推广