pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Laurenz Albe <laurenz.albe@cybertec.at>
To: Siddharth Jain <siddhsql@gmail.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: Question on creating keys on partitioned tables
Date: Mon, 03 Apr 2023 11:53:40 +0200
Message-ID: <8f38668f92ce878b63998aee42d47dd5a91dd653.camel@cybertec.at> (raw)
In-Reply-To: <CAPqV3pRPDM06rGQxaWWeY7XmwdtLOqOzizqo-DRkJWErX8dy1g@mail.gmail.com>
References: <CAPqV3pTAUwjpGpg_=88GR9t8Zd4boUO8acqY4To1pzZFuBiSVQ@mail.gmail.com>
	<d0379fb1269069f2fc7823fb2414cf03b215fdaa.camel@cybertec.at>
	<CAPqV3pTuTV6qPpvWT8f67yd8EPP79vk2Ww5ddJkwmEdWCCQdXA@mail.gmail.com>
	<560122.1680278819@sss.pgh.pa.us>
	<CAPqV3pRPDM06rGQxaWWeY7XmwdtLOqOzizqo-DRkJWErX8dy1g@mail.gmail.com>

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





view thread (6+ messages)

Message-ID: <8f38668f92ce878b63998aee42d47dd5a91dd653.camel@cybertec.at>
Permalink:  ../8f38668f92ce878b63998aee42d47dd5a91dd653.camel@cybertec.at/
Also on:    postgresql.org/message-id/8f38668f92ce878b63998aee42d47dd5a91dd653.camel@cybertec.at

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: laurenz.albe@cybertec.at, siddhsql@gmail.com, tgl@sss.pgh.pa.us
  Subject: Re: Question on creating keys on partitioned tables
  In-Reply-To: <8f38668f92ce878b63998aee42d47dd5a91dd653.camel@cybertec.at>
  References: <CAPqV3pTAUwjpGpg_=88GR9t8Zd4boUO8acqY4To1pzZFuBiSVQ@mail.gmail.com> <d0379fb1269069f2fc7823fb2414cf03b215fdaa.camel@cybertec.at> <CAPqV3pTuTV6qPpvWT8f67yd8EPP79vk2Ww5ddJkwmEdWCCQdXA@mail.gmail.com> <560122.1680278819@sss.pgh.pa.us> <CAPqV3pRPDM06rGQxaWWeY7XmwdtLOqOzizqo-DRkJWErX8dy1g@mail.gmail.com> <8f38668f92ce878b63998aee42d47dd5a91dd653.camel@cybertec.at>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox