解决方式
目前非分片键不允许创建主键或唯一索引。
若一定要创建主键,带上分片键即可。
以下给出一个示例说明:
antdb=# create table sy01(id int,name text) distribute by hash(name);
CREATE TABLE
antdb=# ALTER TABLE sy01 add constraint pk_sy01_1 primary key (id);
ERROR: Cannot create index whose evaluation cannot be enforced to remote nodes
antdb=# ALTER TABLE sy01 add constraint pk_sy01_1 primary key (id,name);
ALTER TABLE
antdb=# \d+ sy01
Table "public.sy01"
Column | Type | Modifiers | Storage | Stats target | Description
--------+---------+-----------+----------+--------------+-------------
id | integer | not null | plain | |
name | text | not null | extended | |
Indexes:
"pk_sy01_1" PRIMARY KEY, btree (id, name)
Distribute By: HASH(name)
Location Nodes: ALL DATANODES