Re: Constraint's NO INHERIT option is ignored in CREATE TABLE LIKE statement

From: Amit Langote <amitlangote09(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Ildar Musin <ildar(at)adjust(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Constraint's NO INHERIT option is ignored in CREATE TABLE LIKE statement
Date: 2020-02-20 02:36:12
Message-ID: CA+HiwqEjSqB5U0JQJSx1X-hbhJG3rvBS5CRVpSyMycjM1tpBRw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, Feb 20, 2020 at 8:02 AM Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> Ildar Musin <ildar(at)adjust(dot)com> writes:
> > My colleague Chris Travers discovered something that looks like a bug.
> > Let's say we have a table with a constraint that is declared as NO INHERIT.
> > ...
> > Now when we want to make a copy of the table structure into a new table
> > the `NO INHERIT` option is ignored.
>
> Hm, I agree that's a bug, since the otherwise-pretty-detailed CREATE TABLE
> LIKE documentation makes no mention of such a difference between original
> and cloned constraint.

By the way, partitioned tables to not allow constraints that are
marked NO INHERIT. For example,

create table b (a int check (a > 0) no inherit) partition by list (a);
ERROR: cannot add NO INHERIT constraint to partitioned table "b"

We must ensure that partitioned tables don't accidentally end up with
one via CREATE TABLE LIKE path. I tested Ildar's patch and things
seem fine, but it might be better to add a test. Attached updated
patch with that taken care of.

Thanks,
Amit

Attachment Content-Type Size
copy_constr_noinherit_v2.patch text/plain 2.4 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Amit Langote 2020-02-20 02:53:09 Re: Constraint's NO INHERIT option is ignored in CREATE TABLE LIKE statement
Previous Message Michael Leonhard 2020-02-20 02:25:10 Add PGURI env var for passing connection string to psql in Docker