jackc/pgx · error
struct doesn't have corresponding row field
Error message
struct doesn't have corresponding row field %s
What it means
Raised from lookupNamedStructFields during name-based struct scanning: a row column has no corresponding struct field (its computed path is nil), so the column-to-field mapping is incomplete. The %s names the row field the struct lacks.
Solutions
- Add a struct field for the column or tag an existing one with db:"<column>"
- Use the lax variant to skip unmatched columns
- Rename or alias the column in the query to match a field
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at rows.go:738 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of jackc/pgx@ec1a0befd2 (2026-08-04).
Data as JSON: /api/errors/6207451f0a7afbd7.
Report an issue: GitHub.
Appendix: source
Thrown at rows.go:738
colNames: joinFieldNames(fldDescs),
}
if cached, ok := namedStructFieldMap.Load(key); ok {
return cached.(*namedStructFields), nil
}
// We could probably do two-levels of caching, where we compute the key -> fields mapping
// for a type only once, cache it by type, then use that to compute the column -> fields
// mapping for a given set of columns.
fieldStack := make([]int, 0, 1)
fields, missingField := computeNamedStructFields(
fldDescs,
t,
make([]structRowField, len(fldDescs)),
&fieldStack,
)
for i, f := range fields {
if f.path == nil {
return nil, fmt.Errorf(
"struct doesn't have corresponding row field %s",
fldDescs[i].Name,
)
}
}
fieldsIface, _ := namedStructFieldMap.LoadOrStore(
key,
&namedStructFields{fields: fields, missingField: missingField},
)
return fieldsIface.(*namedStructFields), nil
}
func joinFieldNames(fldDescs []pgconn.FieldDescription) string {
switch len(fldDescs) {
case 0:
return ""
case 1:View on GitHub (pinned to ec1a0befd2)