想要在主表上创建一个自增的唯一建,保证这个字段在全局唯一(包括所有子表)。
而又想用 PostgreSQL 10版本的分区表的功能。
但在创建表的时候,出现如下问题。看起来是 PostgreSQL 10版本不支持在分区表上创建 primary key 或者 unique。想请教一下,什么方法能实现这个需求呢?
这是在分区表上创建 unique
create table test (id bigserial not null,
name varchar(32),
time timestamp(3) not null,
constraint test_unique_id unique(id))
partition by range (time);
ERROR: unique constraints are not supported on partitioned tables
LINE 4: constraint test_unique_id unique(id))
这是在分区表上创建 primary key
create table test (id bigserial primary key,
name varchar(32),
time timestamp(3) not null)
partition by range (time);
ERROR: primary key constraints are not supported on partitioned tables
LINE 1: create table test (id bigserial primary key