I am trying to replace an existing table with a partitioned version of that table. I want the schema of the new partitioned table to exactly match the existing non-partitioned table so that I can continue to manage the table through Django migrations.
My first attempt at creating the new partitioned table looked something like this:
CREATE TABLE partition_test (
row_index bigint,
id character varying(128) PRIMARY KEY,
vendor_id character varying(128)
) PARTITION BY HASH (vendor_id);
Which results in the following error:
ERROR: unique constraint on partitioned table must include all partitioning columns
DETAIL: PRIMARY KEY constraint on table "product_api_partition_test" lacks column "vendor_id" which is part of the partition key.
I am looking for a work around that will allow me to partition on vendor_id
while keeping row_index
as the primary key.
I tried modifying the primary key as follows, however, Django requires a primary key and does not support composite primary keys. Therefore, both of these options would result in an inconsistency between the true schema and what Django believes is the schema.
CREATE TABLE partition_test (
row_index bigint,
id character varying(128),
vendor_id character varying(128)
PRIMARY KEY (row_index, vendor_id)
) PARTITION BY HASH (vendor_id);
CREATE TABLE api_partition_test (
row_index bigint,
id character varying(128),
vendor_id character varying(128)
) PARTITION BY HASH (vendor_id);
Chris Parker is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.