Skip to content

Commit 1d617a2

Browse files
committed
Change one loop in ATRewriteTable to use 1-based attnums
All TupleDescAttr() calls in tablecmds.c that aren't in loops across all attributes use AttrNumber-style indexes (1-based); there was only one place in ATRewriteTable that was stashing 0-based indexes in a list for later processing. Switch that to use attnums for consistency. Author: jian he <[email protected]> Discussion: https://postgr.es/m/CACJufxEoYA5ScUr2=CmA1xcpaS_1ixneDbEkVU77X1ctGxY2mA@mail.gmail.com
1 parent ce1a75c commit 1d617a2

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

src/backend/commands/tablecmds.c

+5-7
Original file line numberDiff line numberDiff line change
@@ -6189,7 +6189,7 @@ ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap)
61896189
Form_pg_attribute attr = TupleDescAttr(newTupDesc, i);
61906190

61916191
if (attr->attnotnull && !attr->attisdropped)
6192-
notnull_attrs = lappend_int(notnull_attrs, i);
6192+
notnull_attrs = lappend_int(notnull_attrs, attr->attnum);
61936193
}
61946194
if (notnull_attrs)
61956195
needscan = true;
@@ -6370,20 +6370,18 @@ ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap)
63706370
/* Now check any constraints on the possibly-changed tuple */
63716371
econtext->ecxt_scantuple = insertslot;
63726372

6373-
foreach(l, notnull_attrs)
6373+
foreach_int(attn, notnull_attrs)
63746374
{
6375-
int attn = lfirst_int(l);
6376-
6377-
if (slot_attisnull(insertslot, attn + 1))
6375+
if (slot_attisnull(insertslot, attn))
63786376
{
6379-
Form_pg_attribute attr = TupleDescAttr(newTupDesc, attn);
6377+
Form_pg_attribute attr = TupleDescAttr(newTupDesc, attn - 1);
63806378

63816379
ereport(ERROR,
63826380
(errcode(ERRCODE_NOT_NULL_VIOLATION),
63836381
errmsg("column \"%s\" of relation \"%s\" contains null values",
63846382
NameStr(attr->attname),
63856383
RelationGetRelationName(oldrel)),
6386-
errtablecol(oldrel, attn + 1)));
6384+
errtablecol(oldrel, attn)));
63876385
}
63886386
}
63896387

0 commit comments

Comments
 (0)