Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3cca13c

Browse files
committed
Fix another bug in merging of inherited CHECK constraints.
It's not good for an inherited child constraint to be marked connoinherit;that would result in the constraint not propagating to grandchild tables,if any are created later. The code mostly prevented this from happeningbut there was one case that was missed.This is somewhat related to commite55a946, which also tightened checkson constraint merging. Hence, back-patch to 9.2 like that one. This isn'tso much because there's a concrete feature-related reason to stop there,as to avoid having more distinct behaviors than we have to in this area.Amit LangoteDiscussion: <b28ee774-7009-313d-dd55-5bdd81242c41@lab.ntt.co.jp>
1 parentc08521e commit3cca13c

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

‎src/backend/catalog/heap.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2462,6 +2462,17 @@ MergeWithExistingConstraint(Relation rel, char *ccname, Node *expr,
24622462
errmsg("constraint \"%s\" conflicts with non-inherited constraint on relation \"%s\"",
24632463
ccname,RelationGetRelationName(rel))));
24642464

2465+
/*
2466+
* Must not change an existing inherited constraint to "no
2467+
* inherit" status. That's because inherited constraints should
2468+
* be able to propagate to lower-level children.
2469+
*/
2470+
if (con->coninhcount>0&&is_no_inherit)
2471+
ereport(ERROR,
2472+
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
2473+
errmsg("constraint \"%s\" conflicts with inherited constraint on relation \"%s\"",
2474+
ccname,RelationGetRelationName(rel))));
2475+
24652476
/*
24662477
* If the child constraint is "not valid" then cannot merge with a
24672478
* valid parent constraint

‎src/test/regress/expected/inherit.out

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,9 @@ Check constraints:
645645
"p2chk" CHECK (ff1 > 10)
646646
Inherits: p1
647647

648+
-- Test that child does not override inheritable constraints of the parent
649+
create table c2 (constraint p2chk check (ff1 > 10) no inherit) inherits (p1);--fails
650+
ERROR: constraint "p2chk" conflicts with inherited constraint on relation "c2"
648651
drop table p1 cascade;
649652
NOTICE: drop cascades to table c1
650653
-- Tests for casting between the rowtypes of parent and child

‎src/test/regress/sql/inherit.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,9 @@ create table c1 () inherits (p1);
157157
\d p1
158158
\d c1
159159

160+
-- Test that child does not override inheritable constraints of the parent
161+
createtablec2 (constraint p2chkcheck (ff1>10) no inherit) inherits (p1);--fails
162+
160163
droptable p1 cascade;
161164

162165
-- Tests for casting between the rowtypes of parent and child

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp