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 8f38668f92ce878b63998aee42d47dd5a91dd653.camel@cybertec.at
Whole thread Raw
In response to Re: Question on creating keys on partitioned tables  (Siddharth Jain <siddhsql@gmail.com>)
List pgsql-general
On Fri, 2023-03-31 at 10:35 -0700, Siddharth Jain wrote:
> Is following correct?
>
> when a PK is created on (X,Y) on the parent table what happens internally is that the
> command is run individually on each of the child tables. nothing more. nothing less.

If you are talking about inheritance, no.  Creating a constraint on the parent table
has no effect on a child table.

If you are talking about partitioning: If you create a primary key on the partitioned
table, that will be implemented by a partitioned index.  That partitioned index consists
of a unique index for each partition.  So I guess that is more or less what you mean.

There are some differences between a primary key on the partitioned table and a unique
index on each partition:
- the primary key is a constraint, so it can be the target of a foreign key
- the primary key will force a unique index on each new partition
- the primary key keeps you from dropping the unique index on the partitions

Yours,
Laurenz Albe



pgsql-general by date:

Previous
From: Laurenz Albe
Date:
Subject: Re: PostgreSQL
Next
From: Dominique Devienne
Date:
Subject: DEFINER / INVOKER conundrum