@@ -601,7 +601,7 @@ DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId)
601
601
cooked -> skip_validation = false;
602
602
cooked -> is_local = true; /* not used for defaults */
603
603
cooked -> inhcount = 0 ; /* ditto */
604
- cooked -> is_only = false;
604
+ cooked -> is_no_inherit = false;
605
605
cookedDefaults = lappend (cookedDefaults , cooked );
606
606
descriptor -> attrs [attnum - 1 ]-> atthasdef = true;
607
607
}
@@ -661,7 +661,7 @@ DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId)
661
661
*/
662
662
if (rawDefaults || stmt -> constraints )
663
663
AddRelationNewConstraints (rel , rawDefaults , stmt -> constraints ,
664
- true, true, false );
664
+ true, true);
665
665
666
666
/*
667
667
* Clean up. We keep lock on new relation (although it shouldn't be
@@ -1655,7 +1655,7 @@ MergeAttributes(List *schema, List *supers, char relpersistence,
1655
1655
Node * expr ;
1656
1656
1657
1657
/* ignore if the constraint is non-inheritable */
1658
- if (check [i ].cconly )
1658
+ if (check [i ].ccnoinherit )
1659
1659
continue ;
1660
1660
1661
1661
/* adjust varattnos of ccbin here */
@@ -1676,7 +1676,7 @@ MergeAttributes(List *schema, List *supers, char relpersistence,
1676
1676
cooked -> skip_validation = false;
1677
1677
cooked -> is_local = false;
1678
1678
cooked -> inhcount = 1 ;
1679
- cooked -> is_only = false;
1679
+ cooked -> is_no_inherit = false;
1680
1680
constraints = lappend (constraints , cooked );
1681
1681
}
1682
1682
}
@@ -2399,7 +2399,7 @@ rename_constraint_internal(Oid myrelid,
2399
2399
constraintOid );
2400
2400
con = (Form_pg_constraint ) GETSTRUCT (tuple );
2401
2401
2402
- if (myrelid && con -> contype == CONSTRAINT_CHECK && !con -> conisonly )
2402
+ if (myrelid && con -> contype == CONSTRAINT_CHECK && !con -> connoinherit )
2403
2403
{
2404
2404
if (recurse )
2405
2405
{
@@ -4573,7 +4573,7 @@ ATExecAddColumn(List **wqueue, AlteredTableInfo *tab, Relation rel,
4573
4573
* This function is intended for CREATE TABLE, so it processes a
4574
4574
* _list_ of defaults, but we just do one.
4575
4575
*/
4576
- AddRelationNewConstraints (rel , list_make1 (rawEnt ), NIL , false, true, false );
4576
+ AddRelationNewConstraints (rel , list_make1 (rawEnt ), NIL , false, true);
4577
4577
4578
4578
/* Make the additional catalog changes visible */
4579
4579
CommandCounterIncrement ();
@@ -5015,7 +5015,7 @@ ATExecColumnDefault(Relation rel, const char *colName,
5015
5015
* This function is intended for CREATE TABLE, so it processes a
5016
5016
* _list_ of defaults, but we just do one.
5017
5017
*/
5018
- AddRelationNewConstraints (rel , list_make1 (rawEnt ), NIL , false, true, false );
5018
+ AddRelationNewConstraints (rel , list_make1 (rawEnt ), NIL , false, true);
5019
5019
}
5020
5020
}
5021
5021
@@ -5680,16 +5680,11 @@ ATAddCheckConstraint(List **wqueue, AlteredTableInfo *tab, Relation rel,
5680
5680
* omitted from the returned list, which is what we want: we do not need
5681
5681
* to do any validation work. That can only happen at child tables,
5682
5682
* though, since we disallow merging at the top level.
5683
- *
5684
- * Note: we set is_only based on the recurse flag which is false when
5685
- * interpretInhOption() of our statement returns false all the way up
5686
- * in AlterTable and gets passed all the way down to here.
5687
5683
*/
5688
5684
newcons = AddRelationNewConstraints (rel , NIL ,
5689
5685
list_make1 (copyObject (constr )),
5690
- recursing , /* allow_merge */
5691
- !recursing , /* is_local */
5692
- !recurse && !recursing ); /* is_only */
5686
+ recursing , /* allow_merge */
5687
+ !recursing ); /* is_local */
5693
5688
5694
5689
/* Add each to-be-validated constraint to Phase 3's queue */
5695
5690
foreach (lcon , newcons )
@@ -5730,9 +5725,9 @@ ATAddCheckConstraint(List **wqueue, AlteredTableInfo *tab, Relation rel,
5730
5725
return ;
5731
5726
5732
5727
/*
5733
- * Adding an ONLY constraint? No need to find our children
5728
+ * Adding a NO INHERIT constraint? No need to find our children
5734
5729
*/
5735
- if (! recurse && ! recursing )
5730
+ if (constr -> is_no_inherit )
5736
5731
return ;
5737
5732
5738
5733
/*
@@ -5742,6 +5737,16 @@ ATAddCheckConstraint(List **wqueue, AlteredTableInfo *tab, Relation rel,
5742
5737
*/
5743
5738
children = find_inheritance_children (RelationGetRelid (rel ), lockmode );
5744
5739
5740
+ /*
5741
+ * Check if ONLY was specified with ALTER TABLE. If so, allow the
5742
+ * contraint creation only if there are no children currently. Error out
5743
+ * otherwise.
5744
+ */
5745
+ if (!recurse && children != NIL )
5746
+ ereport (ERROR ,
5747
+ (errcode (ERRCODE_INVALID_TABLE_DEFINITION ),
5748
+ errmsg ("constraint must be added to child tables too" )));
5749
+
5745
5750
foreach (child , children )
5746
5751
{
5747
5752
Oid childrelid = lfirst_oid (child );
@@ -6127,7 +6132,7 @@ ATAddForeignKeyConstraint(AlteredTableInfo *tab, Relation rel,
6127
6132
NULL ,
6128
6133
true, /* islocal */
6129
6134
0 , /* inhcount */
6130
- false); /* isonly */
6135
+ false); /* isnoinherit */
6131
6136
6132
6137
/*
6133
6138
* Create the triggers that will enforce the constraint.
@@ -6998,8 +7003,7 @@ ATExecDropConstraint(Relation rel, const char *constrName,
6998
7003
ScanKeyData key ;
6999
7004
HeapTuple tuple ;
7000
7005
bool found = false;
7001
- bool is_check_constraint = false;
7002
- bool is_only_constraint = false;
7006
+ bool is_no_inherit_constraint = false;
7003
7007
7004
7008
/* At top level, permission check was done in ATPrepCmd, else do it */
7005
7009
if (recursing )
@@ -7033,15 +7037,7 @@ ATExecDropConstraint(Relation rel, const char *constrName,
7033
7037
errmsg ("cannot drop inherited constraint \"%s\" of relation \"%s\"" ,
7034
7038
constrName , RelationGetRelationName (rel ))));
7035
7039
7036
- /* Right now only CHECK constraints can be inherited */
7037
- if (con -> contype == CONSTRAINT_CHECK )
7038
- is_check_constraint = true;
7039
-
7040
- if (con -> conisonly )
7041
- {
7042
- Assert (is_check_constraint );
7043
- is_only_constraint = true;
7044
- }
7040
+ is_no_inherit_constraint = con -> connoinherit ;
7045
7041
7046
7042
/*
7047
7043
* Perform the actual constraint deletion
@@ -7084,7 +7080,7 @@ ATExecDropConstraint(Relation rel, const char *constrName,
7084
7080
* routines, we have to do this one level of recursion at a time; we can't
7085
7081
* use find_all_inheritors to do it in one pass.
7086
7082
*/
7087
- if (is_check_constraint && ! is_only_constraint )
7083
+ if (! is_no_inherit_constraint )
7088
7084
children = find_inheritance_children (RelationGetRelid (rel ), lockmode );
7089
7085
else
7090
7086
children = NIL ;
@@ -9250,8 +9246,8 @@ MergeConstraintsIntoExisting(Relation child_rel, Relation parent_rel)
9250
9246
if (parent_con -> contype != CONSTRAINT_CHECK )
9251
9247
continue ;
9252
9248
9253
- /* if the parent's constraint is marked ONLY , it's not inherited */
9254
- if (parent_con -> conisonly )
9249
+ /* if the parent's constraint is marked NO INHERIT , it's not inherited */
9250
+ if (parent_con -> connoinherit )
9255
9251
continue ;
9256
9252
9257
9253
/* Search for a child constraint matching this one */
@@ -9281,8 +9277,8 @@ MergeConstraintsIntoExisting(Relation child_rel, Relation parent_rel)
9281
9277
RelationGetRelationName (child_rel ),
9282
9278
NameStr (parent_con -> conname ))));
9283
9279
9284
- /* If the constraint is "only " then cannot merge */
9285
- if (child_con -> conisonly )
9280
+ /* If the constraint is "no inherit " then cannot merge */
9281
+ if (child_con -> connoinherit )
9286
9282
ereport (ERROR ,
9287
9283
(errcode (ERRCODE_INVALID_OBJECT_DEFINITION ),
9288
9284
errmsg ("constraint \"%s\" conflicts with non-inherited constraint on child table \"%s\"" ,
0 commit comments