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
diff --git a/src/backend/parser/parse_utilcmd.c b/src/backend/parser/parse_utilcmd.c
index 2406ca7a5d..d75ec6766a 100644
--- a/src/backend/parser/parse_utilcmd.c
+++ b/src/backend/parser/parse_utilcmd.c
@@ -1154,6 +1154,7 @@ transformTableLikeClause(CreateStmtContext *cxt, TableLikeClause *table_like_cla
n->contype = CONSTR_CHECK;
n->location = -1;
n->conname = pstrdup(ccname);
+ n->is_no_inherit = tupleDesc->constr->check[ccnum].ccnoinherit;
n->raw_expr = NULL;
n->cooked_expr = nodeToString(ccbin_node);
cxt->ckconstraints = lappend(cxt->ckconstraints, n);