I want to create a partitioned table in the PostgreSQL database and run the below query.
CREATE TABLE tracking_trackingdata (
"id" uuid NOT NULL,
tracking_id varchar(100) NOT NULL UNIQUE,
dynamic_url_object_id bigint NOT NULL,
ip_address inet NOT NULL,
scan_time timestamp with time zone NOT NULL,
created timestamp with time zone NOT NULL,
modified timestamp with time zone NOT NULL,
PRIMARY KEY ( "id", scan_time )
) PARTITION BY RANGE ( scan_time )
but it keeps on giving the error
[
0A000
] ERROR: unique constraint on partitioned table must include all partitioning columns Detail:UNIQUE
constraint on tabletracking_trackingdata
lacks columnscan_time
which is part of the partition key.
The scan_time
could be duplicated while the id
column will always be unique. I want to have a partition by scan_time
, how can I apply a unique constraint on it when there can be duplicate entries at the same time? I have also passed the id
and scan_time
columns to the PRIMARY KEY
constraint so that the combination of both will always be unique.