Constraint's NO INHERIT option is ignored in CREATE TABLE LIKE statement
Ildar Musin <ildar@adjust.com>
From: Ildar Musin <ildar@adjust.com>
To: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2020-02-19T13:59:40Z
Lists: pgsql-hackers
Attachments
- copy_constr_noinherit.patch (text/x-patch) patch
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
Commits
-
Ensure that CREATE TABLE LIKE copies any NO INHERIT constraint property.
- cacef172237f 13.0 landed