@@ -96,8 +96,9 @@ static Oid AddNewRelationType(const char *typeName,
9696static void RelationRemoveInheritance (Oid relid );
9797static void StoreRelCheck (Relation rel ,char * ccname ,Node * expr ,
9898bool is_validated ,bool is_local ,int inhcount ,
99- bool is_no_inherit );
100- static void StoreConstraints (Relation rel ,List * cooked_constraints );
99+ bool is_no_inherit ,bool is_internal );
100+ static void StoreConstraints (Relation rel ,List * cooked_constraints ,
101+ bool is_internal );
101102static bool MergeWithExistingConstraint (Relation rel ,char * ccname ,Node * expr ,
102103bool allow_merge ,bool is_local ,
103104bool is_no_inherit );
@@ -1302,7 +1303,7 @@ heap_create_with_catalog(const char *relname,
13021303 * entry, so the relation must be valid and self-consistent at this point.
13031304 * In particular, there are not yet constraints and defaults anywhere.
13041305 */
1305- StoreConstraints (new_rel_desc ,cooked_constraints );
1306+ StoreConstraints (new_rel_desc ,cooked_constraints , is_internal );
13061307
13071308/*
13081309 * If there's a special on-commit action, remember it
@@ -1836,7 +1837,8 @@ heap_drop_with_catalog(Oid relid)
18361837 * Store a default expression for column attnum of relation rel.
18371838 */
18381839void
1839- StoreAttrDefault (Relation rel ,AttrNumber attnum ,Node * expr )
1840+ StoreAttrDefault (Relation rel ,AttrNumber attnum ,
1841+ Node * expr ,bool is_internal )
18401842{
18411843char * adbin ;
18421844char * adsrc ;
@@ -1928,6 +1930,17 @@ StoreAttrDefault(Relation rel, AttrNumber attnum, Node *expr)
19281930 * Record dependencies on objects used in the expression, too.
19291931 */
19301932recordDependencyOnExpr (& defobject ,expr ,NIL ,DEPENDENCY_NORMAL );
1933+
1934+ /*
1935+ * Post creation hook for attribute defaults.
1936+ *
1937+ * XXX. ALTER TABLE ALTER COLUMN SET/DROP DEFAULT is implemented
1938+ * with a couple of deletion/creation of the attribute's default entry,
1939+ * so the callee should check existence of an older version of this
1940+ * entry if it needs to distinguish.
1941+ */
1942+ InvokeObjectPostCreateHookArg (AttrDefaultRelationId ,
1943+ RelationGetRelid (rel ),attnum ,is_internal );
19311944}
19321945
19331946/*
@@ -1939,7 +1952,7 @@ StoreAttrDefault(Relation rel, AttrNumber attnum, Node *expr)
19391952static void
19401953StoreRelCheck (Relation rel ,char * ccname ,Node * expr ,
19411954bool is_validated ,bool is_local ,int inhcount ,
1942- bool is_no_inherit )
1955+ bool is_no_inherit , bool is_internal )
19431956{
19441957char * ccbin ;
19451958char * ccsrc ;
@@ -2023,7 +2036,8 @@ StoreRelCheck(Relation rel, char *ccname, Node *expr,
20232036ccsrc ,/* Source form of check constraint */
20242037is_local ,/* conislocal */
20252038inhcount ,/* coninhcount */
2026- is_no_inherit );/* connoinherit */
2039+ is_no_inherit ,/* connoinherit */
2040+ is_internal );/* internally constructed? */
20272041
20282042pfree (ccbin );
20292043pfree (ccsrc );
@@ -2038,7 +2052,7 @@ StoreRelCheck(Relation rel, char *ccname, Node *expr,
20382052 * and StoreRelCheck (see AddRelationNewConstraints()).
20392053 */
20402054static void
2041- StoreConstraints (Relation rel ,List * cooked_constraints )
2055+ StoreConstraints (Relation rel ,List * cooked_constraints , bool is_internal )
20422056{
20432057int numchecks = 0 ;
20442058ListCell * lc ;
@@ -2060,11 +2074,12 @@ StoreConstraints(Relation rel, List *cooked_constraints)
20602074switch (con -> contype )
20612075{
20622076case CONSTR_DEFAULT :
2063- StoreAttrDefault (rel ,con -> attnum ,con -> expr );
2077+ StoreAttrDefault (rel ,con -> attnum ,con -> expr , is_internal );
20642078break ;
20652079case CONSTR_CHECK :
20662080StoreRelCheck (rel ,con -> name ,con -> expr , !con -> skip_validation ,
2067- con -> is_local ,con -> inhcount ,con -> is_no_inherit );
2081+ con -> is_local ,con -> inhcount ,
2082+ con -> is_no_inherit ,is_internal );
20682083numchecks ++ ;
20692084break ;
20702085default :
@@ -2090,6 +2105,7 @@ StoreConstraints(Relation rel, List *cooked_constraints)
20902105 * newConstraints: list of Constraint nodes
20912106 * allow_merge: TRUE if check constraints may be merged with existing ones
20922107 * is_local: TRUE if definition is local, FALSE if it's inherited
2108+ * is_internal: TRUE if result of some internal process, not a user request
20932109 *
20942110 * All entries in newColDefaults will be processed. Entries in newConstraints
20952111 * will be processed only if they are CONSTR_CHECK type.
@@ -2107,7 +2123,8 @@ AddRelationNewConstraints(Relation rel,
21072123List * newColDefaults ,
21082124List * newConstraints ,
21092125bool allow_merge ,
2110- bool is_local )
2126+ bool is_local ,
2127+ bool is_internal )
21112128{
21122129List * cookedConstraints = NIL ;
21132130TupleDesc tupleDesc ;
@@ -2170,7 +2187,7 @@ AddRelationNewConstraints(Relation rel,
21702187(IsA (expr ,Const )&& ((Const * )expr )-> constisnull ))
21712188continue ;
21722189
2173- StoreAttrDefault (rel ,colDef -> attnum ,expr );
2190+ StoreAttrDefault (rel ,colDef -> attnum ,expr , is_internal );
21742191
21752192cooked = (CookedConstraint * )palloc (sizeof (CookedConstraint ));
21762193cooked -> contype = CONSTR_DEFAULT ;
@@ -2296,7 +2313,7 @@ AddRelationNewConstraints(Relation rel,
22962313 * OK, store it.
22972314 */
22982315StoreRelCheck (rel ,ccname ,expr , !cdef -> skip_validation ,is_local ,
2299- is_local ?0 :1 ,cdef -> is_no_inherit );
2316+ is_local ?0 :1 ,cdef -> is_no_inherit , is_internal );
23002317
23012318numchecks ++ ;
23022319