From 8b99e21fda58a0189547139b4aa2ba9f87eabbb7 Mon Sep 17 00:00:00 2001 From: jian he Date: Thu, 20 Mar 2025 12:06:41 +0800 Subject: [PATCH v5 2/2] minor change ATRewriteTable make notnull_attrs and notnull_virtual_attrs both are 1 based. make sure TupleDescAttr need minus 1. --- src/backend/commands/tablecmds.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 0751c0d627c..04806c068df 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -6194,7 +6194,7 @@ ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap) if (attr->attnotnull && !attr->attisdropped) { if (attr->attgenerated != ATTRIBUTE_GENERATED_VIRTUAL) - notnull_attrs = lappend_int(notnull_attrs, i); + notnull_attrs = lappend_int(notnull_attrs, attr->attnum); else notnull_virtual_attrs = lappend_int(notnull_virtual_attrs, attr->attnum); @@ -6405,20 +6405,18 @@ ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap) /* Now check any constraints on the possibly-changed tuple */ econtext->ecxt_scantuple = insertslot; - foreach(l, notnull_attrs) + foreach_int(attn, notnull_attrs) { - int attn = lfirst_int(l); - - if (slot_attisnull(insertslot, attn + 1)) + if (slot_attisnull(insertslot, attn)) { - Form_pg_attribute attr = TupleDescAttr(newTupDesc, attn); + Form_pg_attribute attr = TupleDescAttr(newTupDesc, attn - 1); ereport(ERROR, (errcode(ERRCODE_NOT_NULL_VIOLATION), errmsg("column \"%s\" of relation \"%s\" contains null values", NameStr(attr->attname), RelationGetRelationName(oldrel)), - errtablecol(oldrel, attn + 1))); + errtablecol(oldrel, attn))); } } -- 2.34.1