Re: Partitioning on the date part of a timestamp & PK issues - Mailing list pgsql-admin

From David G. Johnston
Subject Re: Partitioning on the date part of a timestamp & PK issues
Date
Msg-id CAKFQuwapgPw3SJf2Mk1ePbCELOyG4enXatfVx0hz_SAfu0=tog@mail.gmail.com
Whole thread Raw
In response to Partitioning on the date part of a timestamp & PK issues  (Wells Oliver <wells.oliver@gmail.com>)
List pgsql-admin
On Thu, Jul 15, 2021 at 1:10 PM Wells Oliver <wells.oliver@gmail.com> wrote:

    primary key (guid, tid, seq)
) partition by range (extract(date from ts));

The PK is the PK, so I'm not sure what options I have there.

You are indirectly hitting the documented limitation that:

"Unique constraints (and hence primary keys) on partitioned tables must include all the partition key columns. This limitation exists because the individual indexes making up the constraint can only directly enforce uniqueness within their own partitions; therefore, the partition structure itself must guarantee that there are not duplicates in different partitions."


So if you want to enforce PKs here you need to both add the physical column to the table AND add the same to your primary key.

David J.

pgsql-admin by date:

Previous
From: Holger Jakobs
Date:
Subject: Re: Partitioning on the date part of a timestamp & PK issues
Next
From: Ron
Date:
Subject: Re: Partitioning on the date part of a timestamp & PK issues