static void truncate_check_rel(Relation rel);
static List *MergeAttributes(List *schema, List *supers, char relpersistence,
- List **supOids, List **supconstr, int *supOidCount);
+ List **supOids, List **supconstr, int *supOidCount);
static bool MergeCheckConstraint(List *constraints, char *name, Node *expr);
static bool change_varattnos_walker(Node *node, const AttrNumber *newattno);
static void MergeAttributesIntoExisting(Relation child_rel, Relation parent_rel,
if (colDef->is_not_null)
{
/*
- * Check list of NOT NULL constraints for the current
- * column name. There should only one Constraint node, so
- * we give up immediately when we've found a constraint.
+ * Check list of explicit defined NOT NULL constraints for the
+ * current column name. There should be only one Constraint node,
+ * so we give up immediately when we've found a constraint.
*/
ListCell *nnconstrptr;
cooked->contype = CONSTR_NOTNULL;
cooked->attnum = attnum;
cooked->expr = NULL;
- cooked->is_local = colDef->is_local;
- cooked->inhcount = colDef->inhcount;
+ cooked->is_local = true;
+ cooked->inhcount = 0;
nnconstraints = lappend(nnconstraints, cooked);
/*
/* Mark the column as locally defined */
def->is_local = true;
+
/* Merge of NOT NULL constraints = OR 'em together */
+ if (!def->is_not_null && newdef->is_not_null)
+ {
+ ListCell *constrCell;
+
+ /*
+ * There must be a locally defined Constraint node attached
+ * to this column definition. We need to inject it to the
+ * list of constraints, at least to keep a possible
+ * assigned constraint name. We do this by adding the
+ * Constraint node to the column's own list of constraints.
+ * Such constraints are treated as locally defined and will
+ * be handled later when the target table get's created.
+ */
+ foreach (constrCell, newdef->constraints)
+ {
+ Constraint *newnnconstr = lfirst(constrCell);
+ if (newnnconstr->contype == CONSTR_NOTNULL)
+ {
+ def->constraints = lappend(def->constraints,
+ newnnconstr);
+ break;
+ }
+ }
+ }
+
def->is_not_null |= newdef->is_not_null;
/* If new def has a default, override previous default */
if (newdef->raw_default != NULL)
attributeTuple,
constraintTuple;
List *constraints;
- List *connames;
bool found = false;
/*
create table child(f1 int not null, f2 text not null) inherits(parent1, parent2);
-- show constraint info
-select conrelid::regclass, conname, contype, coninhcount, conislocal from pg_constraint where contype = 'n' order by 2;
+select conrelid::regclass, conname, contype, coninhcount, conislocal, conkey from pg_constraint where contype = 'n' order by 2;
-- also drops child table
drop table parent1 cascade;