Skip to content

fix: use ad.adrelid instead of pg_attrdef OID in pg_get_expr#325

Open
simPod wants to merge 1 commit intonette:v3.2from
simPod:pg-fix
Open

fix: use ad.adrelid instead of pg_attrdef OID in pg_get_expr#325
simPod wants to merge 1 commit intonette:v3.2from
simPod:pg-fix

Conversation

@simPod
Copy link
Copy Markdown

@simPod simPod commented Apr 3, 2026

pg_get_expr requires the OID of the relation that owns the expression as its second argument. Using 'pg_catalog.pg_attrdef'::regclass passes the OID of the catalog table itself, which causes "invalid attnum" errors when tables have GENERATED ALWAYS AS stored columns.

The correct relation OID is ad.adrelid (the table the default/generated expression belongs to). Line 152 already uses ad.adrelid correctly for the same function — this aligns lines 151 and 155.

  • bug fix

Fixes: SQLSTATE[XX000]: Internal error: 7 ERROR: invalid attnum 9
for relation "pg_attrdef"

pg_get_expr requires the OID of the relation that owns the expression
as its second argument. Using 'pg_catalog.pg_attrdef'::regclass passes
the OID of the catalog table itself, which causes "invalid attnum"
errors when tables have GENERATED ALWAYS AS stored columns.

The correct relation OID is ad.adrelid (the table the default/generated
expression belongs to). The autoincrement detection on the same line
already uses ad.adrelid correctly — this aligns the other two calls.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant