]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
SET NOT NULL: Call object-alter hook only after the catalog change
authorÁlvaro Herrera <alvherre@kurilemu.de>
Fri, 20 Mar 2026 13:38:50 +0000 (14:38 +0100)
committerÁlvaro Herrera <alvherre@kurilemu.de>
Fri, 20 Mar 2026 13:38:50 +0000 (14:38 +0100)
... otherwise, the function invoked by the hook might consult the
catalog and not see that the new constraint exists.

This relies on set_attnotnull doing CommandCounterIncrement()
after successfully modifying the catalog.

Oversight in commit 14e87ffa5c54.

Author: Artur Zakirov <zaartur@gmail.com>
Backpatch-through: 18
Discussion: https://postgr.es/m/CAKNkYnxUPCJk-3Xe0A3rmCC8B8V8kqVJbYMVN6ySGpjs_qd7dQ@mail.gmail.com

src/backend/commands/tablecmds.c

index 8d55acb64a22df8fe4ca594f306b9088788ed9dd..219f604df7b116b2b752a71597d4e61674ad7f3e 100644 (file)
@@ -8137,12 +8137,12 @@ ATExecSetNotNull(List **wqueue, Relation rel, char *conName, char *colName,
        ccon = linitial(cooked);
        ObjectAddressSet(address, ConstraintRelationId, ccon->conoid);
 
-       InvokeObjectPostAlterHook(RelationRelationId,
-                                                         RelationGetRelid(rel), attnum);
-
        /* Mark pg_attribute.attnotnull for the column and queue validation */
        set_attnotnull(wqueue, rel, attnum, true, true);
 
+       InvokeObjectPostAlterHook(RelationRelationId,
+                                                         RelationGetRelid(rel), attnum);
+
        /*
         * Recurse to propagate the constraint to children that don't have one.
         */