Re: Question on creating keys on partitioned tables - Mailing list pgsql-general

From Laurenz Albe
Subject Re: Question on creating keys on partitioned tables
Date
Msg-id d0379fb1269069f2fc7823fb2414cf03b215fdaa.camel@cybertec.at
Whole thread Raw
In response to Question on creating keys on partitioned tables  (Siddharth Jain <siddhsql@gmail.com>)
Responses Re: Question on creating keys on partitioned tables  (Siddharth Jain <siddhsql@gmail.com>)
List pgsql-general
On Thu, 2023-03-30 at 17:05 -0700, Siddharth Jain wrote:
> I have this question. Say I create a partitioned table on column X.
>
> Option 1:
>
> I add a primary key on (X,Y). Y is another column. Even though Y is a globally unique PK (global meaning it is unique
acrosspartitions, not just in one partition), Postgres does not allow me to 
> create a PK on Y in a partitioned table.
>
> Option 2:
>
> I add PK on Y on each of the partitions
>
> Are these not equivalent? If not, which is better and why?

No, they are not equivalent.

Option 2 comes closer to guaranteeing uniqueness for column X, so use that.

> PS: This is what my best friend had to say:
>
> [...] If you are using the "table inheritance" approach [...]

Don't even consider that.  Declarative partitioning is so much better.

Yours,
Laurenz Albe



pgsql-general by date:

Previous
From: Arnaud Lesauvage
Date:
Subject: Cannot terminate backend
Next
From: Laurenz Albe
Date:
Subject: Re: Cannot terminate backend