Thread

Commits

  1. Ensure that CREATE TABLE LIKE copies any NO INHERIT constraint property.

  1. Constraint's NO INHERIT option is ignored in CREATE TABLE LIKE statement

    Ildar Musin <ildar@adjust.com> — 2020-02-19T13:59:40Z

    Hi hackers,
    
    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.
    
    CREATE TABLE test (
        x INT CHECK (x > 0) NO INHERIT
    );
    \d test
                    Table "public.test"
     Column |  Type   | Collation | Nullable | Default
    --------+---------+-----------+----------+---------
     x      | integer |           |          |
    Check constraints:
        "test_x_check1" CHECK (x > 0) NO INHERIT
    
    Now when we want to make a copy of the table structure into a new table
    the `NO INHERIT` option is ignored.
    
    CREATE TABLE test2 (LIKE test INCLUDING CONSTRAINTS);
    \d test2
                   Table "public.test2"
     Column |  Type   | Collation | Nullable | Default
    --------+---------+-----------+----------+---------
     x      | integer |           |          |
    Check constraints:
        "test_x_check1" CHECK (x > 0)
    
    Is this a bug or expected behaviour? Just in case I've attached a patch
    that fixes this.
    
    Regards,
    Ildar
    
  2. Re: Constraint's NO INHERIT option is ignored in CREATE TABLE LIKE statement

    Tom Lane <tgl@sss.pgh.pa.us> — 2020-02-19T23:02:21Z

    Ildar Musin <ildar@adjust.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.
    
    However, I'd be disinclined to back-patch, since it's barely possible
    somebody out there is depending on the existing behavior.
    
    			regards, tom lane
    
    
    
    
  3. Re: Constraint's NO INHERIT option is ignored in CREATE TABLE LIKE statement

    David G. Johnston <david.g.johnston@gmail.com> — 2020-02-19T23:20:19Z

    On Wed, Feb 19, 2020 at 4:02 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
    
    > Ildar Musin <ildar@adjust.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.
    >
    > However, I'd be disinclined to back-patch, since it's barely possible
    > somebody out there is depending on the existing behavior.
    >
    
    Not sure I agree with the premise that it is not supposed to be copied; is
    there some other object type the allows NO INHERIT that isn't copied when
    CREATE TABLE LIKE is used and check constraints are the odd ones out?
    
    Inheritance is what NO INHERIT is about and CREATE TABLE LIKE pointedly
    doesn't setup an inheritance structure.  The documentation seems ok since
    saying that NO INHERIT is ignored when inheritance is not being used seems
    self-evident.  Sure, maybe some clarity here could be had, but its not like
    this comes up with any regularity.
    
    David J.
    
  4. Re: Constraint's NO INHERIT option is ignored in CREATE TABLE LIKE statement

    Amit Langote <amitlangote09@gmail.com> — 2020-02-20T02:36:12Z

    On Thu, Feb 20, 2020 at 8:02 AM Tom Lane <tgl@sss.pgh.pa.us> wrote:
    > Ildar Musin <ildar@adjust.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
    
  5. Re: Constraint's NO INHERIT option is ignored in CREATE TABLE LIKE statement

    Amit Langote <amitlangote09@gmail.com> — 2020-02-20T02:53:09Z

    On Thu, Feb 20, 2020 at 8:20 AM David G. Johnston
    <david.g.johnston@gmail.com> wrote:
    > On Wed, Feb 19, 2020 at 4:02 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
    >> Ildar Musin <ildar@adjust.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.
    >>
    >> However, I'd be disinclined to back-patch, since it's barely possible
    >> somebody out there is depending on the existing behavior.
    >
    > Not sure I agree with the premise that it is not supposed to be copied; is there some other object type the allows NO INHERIT that isn't copied when CREATE TABLE LIKE is used and check constraints are the odd ones out?
    
    Syntax currently allows only CHECK constraints to be marked NO INHERIT.
    
    Thanks,
    Amit
    
    
    
    
  6. Re: Constraint's NO INHERIT option is ignored in CREATE TABLE LIKE statement

    Tom Lane <tgl@sss.pgh.pa.us> — 2020-03-10T18:55:20Z

    Amit Langote <amitlangote09@gmail.com> writes:
    > On Thu, Feb 20, 2020 at 8:20 AM David G. Johnston
    > <david.g.johnston@gmail.com> wrote:
    >> Not sure I agree with the premise that it is not supposed to be copied; is there some other object type the allows NO INHERIT that isn't copied when CREATE TABLE LIKE is used and check constraints are the odd ones out?
    
    > Syntax currently allows only CHECK constraints to be marked NO INHERIT.
    
    Hearing no further comments, pushed, with a bit of cosmetic polishing.
    
    			regards, tom lane