@@ -6189,7 +6189,7 @@ ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap)
6189
6189
Form_pg_attribute attr = TupleDescAttr(newTupDesc, i);
6190
6190
6191
6191
if (attr->attnotnull && !attr->attisdropped)
6192
- notnull_attrs = lappend_int(notnull_attrs, i );
6192
+ notnull_attrs = lappend_int(notnull_attrs, attr->attnum );
6193
6193
}
6194
6194
if (notnull_attrs)
6195
6195
needscan = true;
@@ -6370,20 +6370,18 @@ ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap)
6370
6370
/* Now check any constraints on the possibly-changed tuple */
6371
6371
econtext->ecxt_scantuple = insertslot;
6372
6372
6373
- foreach(l , notnull_attrs)
6373
+ foreach_int(attn , notnull_attrs)
6374
6374
{
6375
- int attn = lfirst_int(l);
6376
-
6377
- if (slot_attisnull(insertslot, attn + 1))
6375
+ if (slot_attisnull(insertslot, attn))
6378
6376
{
6379
- Form_pg_attribute attr = TupleDescAttr(newTupDesc, attn);
6377
+ Form_pg_attribute attr = TupleDescAttr(newTupDesc, attn - 1 );
6380
6378
6381
6379
ereport(ERROR,
6382
6380
(errcode(ERRCODE_NOT_NULL_VIOLATION),
6383
6381
errmsg("column \"%s\" of relation \"%s\" contains null values",
6384
6382
NameStr(attr->attname),
6385
6383
RelationGetRelationName(oldrel)),
6386
- errtablecol(oldrel, attn + 1 )));
6384
+ errtablecol(oldrel, attn)));
6387
6385
}
6388
6386
}
6389
6387
0 commit comments