aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/backend/catalog/heap.c11
-rw-r--r--src/test/regress/expected/inherit.out3
-rw-r--r--src/test/regress/sql/inherit.sql3
3 files changed, 17 insertions, 0 deletions
diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c
index ea06a5739a8..0cf7b9eb626 100644
--- a/src/backend/catalog/heap.c
+++ b/src/backend/catalog/heap.c
@@ -2463,6 +2463,17 @@ MergeWithExistingConstraint(Relation rel, char *ccname, Node *expr,
ccname, RelationGetRelationName(rel))));
/*
+ * Must not change an existing inherited constraint to "no
+ * inherit" status. That's because inherited constraints should
+ * be able to propagate to lower-level children.
+ */
+ if (con->coninhcount > 0 && is_no_inherit)
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
+ errmsg("constraint \"%s\" conflicts with inherited constraint on relation \"%s\"",
+ ccname, RelationGetRelationName(rel))));
+
+ /*
* If the child constraint is "not valid" then cannot merge with a
* valid parent constraint
*/
diff --git a/src/test/regress/expected/inherit.out b/src/test/regress/expected/inherit.out
index 9d374fe6c4a..df7cba6614d 100644
--- a/src/test/regress/expected/inherit.out
+++ b/src/test/regress/expected/inherit.out
@@ -645,6 +645,9 @@ Check constraints:
"p2chk" CHECK (ff1 > 10)
Inherits: p1
+-- Test that child does not override inheritable constraints of the parent
+create table c2 (constraint p2chk check (ff1 > 10) no inherit) inherits (p1); --fails
+ERROR: constraint "p2chk" conflicts with inherited constraint on relation "c2"
drop table p1 cascade;
NOTICE: drop cascades to table c1
-- Tests for casting between the rowtypes of parent and child
diff --git a/src/test/regress/sql/inherit.sql b/src/test/regress/sql/inherit.sql
index 6b1df754a62..f45aab1ac69 100644
--- a/src/test/regress/sql/inherit.sql
+++ b/src/test/regress/sql/inherit.sql
@@ -157,6 +157,9 @@ create table c1 () inherits (p1);
\d p1
\d c1
+-- Test that child does not override inheritable constraints of the parent
+create table c2 (constraint p2chk check (ff1 > 10) no inherit) inherits (p1); --fails
+
drop table p1 cascade;
-- Tests for casting between the rowtypes of parent and child