I did some refactoring on transformColumnDefinition since transformColumnDefinition only deals with a single ColumnDef. and serial/primary/identity cannot allow not-null no inherit. We can preliminary iterate through ColumnDef->constraints to check that ColumnDef can allow not-null no inherit or not. if not allowed, then error out at CONSTR_NOTNULL. please check attached.
in MergeConstraintsIntoExisting
we can
while (HeapTupleIsValid(child_tuple = systable_getnext(child_scan)))
{
Form_pg_constraint child_con = (Form_pg_constraint)
GETSTRUCT(child_tuple);
HeapTuple child_copy;
if (child_con->contype != parent_con->contype)
continue;
if (child_con->connoinherit)
ereport(ERROR,
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
errmsg("constraint \"%s\" conflicts with
non-inherited constraint on child table \"%s\"",
NameStr(child_con->conname),
RelationGetRelationName(child_rel))));
if (parent_con->convalidated && !child_con->convalidated)
ereport(ERROR,
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
errmsg("constraint \"%s\" conflicts with NOT
VALID constraint on child table \"%s\"",
NameStr(child_con->conname),
RelationGetRelationName(child_rel))));
}
error out earlier, save some cache search cycle.
MergeConstraintsIntoExisting comment says
" * XXX See MergeWithExistingConstraint too if you change this code."
we actually did change the MergeConstraintsIntoExisting, not change
MergeWithExistingConstraint
but it seems MergeWithExistingConstraint does not deal with CONSTRAINT_NOTNULL.
So I guess the comments are fine.
previously, we mentioned adding some domain tests at [1].
but it seems v8, we don't have domain related regression tests.
[1]
https://www.postgresql.org/message-id/202409252014.74iepgsyuyws%40alvherre.pgsql
v8-0001-transformColumnDefinition-minor-refactor.no-cfbot
Description: Binary data
