Postgresql: LIKE and partition by fields of the initial table
-
23-02-2021 - |
题
I have an already existing table which I want to partition, looking at the documentation I see that this cannot happen, so I re-created the table and try to partition that:
CREATE TABLE tableB (LIKE tableA INCLUDING ALL) PARTITION BY range (field1_in_tableA, field2_in_tableA);
but I am getting:
ERROR: insufficient columns in PRIMARY KEY constraint definition
DETAIL: PRIMARY KEY constraint on table "tableB" lacks column "field1_in_tableA" which is part of the partition key.
Is there any workaround to this?
解决方案
If you have a primary key, then you can't partition by a key which is not part of the primary key. Do you want a primary key on the new table? If so, you have to either add field1_in_tableA to the primary key, or remove it from the partitioning key.
不隶属于 dba.stackexchange