From 6958077ceb934f5a0c00f95b673fb86d5a7dde95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Herrera?= Date: Fri, 20 Mar 2026 14:38:50 +0100 Subject: [PATCH] SET NOT NULL: Call object-alter hook only after the catalog change ... 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 Backpatch-through: 18 Discussion: https://postgr.es/m/CAKNkYnxUPCJk-3Xe0A3rmCC8B8V8kqVJbYMVN6ySGpjs_qd7dQ@mail.gmail.com --- src/backend/commands/tablecmds.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index dd2b4a51076..9b0aad95a0a 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -8050,12 +8050,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. */