jackc/pgx · error
scan target type changed
Error message
scan target type changed
What it means
Sentinel ErrScanTargetTypeChanged: a cached scan plan was invoked with a destination whose concrete type no longer matches the type the plan was built for (e.g. a *bool plan receiving a *string). It guards against type confusion between plan selection and execution; the mismatched destination type is the faulty input and usually indicates a driver-internal caching bug rather than user error.
Solutions
- If it surfaces in application code, report it as a pgx issue with the types involved
- Ensure the same destination variable/type is used between Rows.Scan planning and scanning
Defensive patterns
Strategy: try-catch
When it happens
Trigger: Thrown at pgtype/pgtype.go:1171 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/bc8f80336d2307b3.
Report an issue: GitHub.
Appendix: source
Thrown at pgtype/pgtype.go:1171
codec = ByteaCodec{}
}
}
return &pointerEmptyInterfaceScanPlan{codec: codec, m: m, oid: oid, formatCode: formatCode}
}
return &scanPlanFail{m: m, oid: oid, formatCode: formatCode}
}
func (m *Map) Scan(oid uint32, formatCode int16, src []byte, dst any) error {
if dst == nil {
return nil
}
plan := m.PlanScan(oid, formatCode, dst)
return plan.Scan(src, dst)
}
var ErrScanTargetTypeChanged = errors.New("scan target type changed")
func codecScan(codec Codec, m *Map, oid uint32, format int16, src []byte, dst any) error {
scanPlan := codec.PlanScan(m, oid, format, dst)
if scanPlan == nil {
return fmt.Errorf("PlanScan did not find a plan")
}
return scanPlan.Scan(src, dst)
}
func codecDecodeToTextFormat(codec Codec, m *Map, oid uint32, format int16, src []byte) (driver.Value, error) {
if src == nil {
return nil, nil
}
if format == TextFormatCode {
return string(src), nil
} else {
value, err := codec.DecodeValue(m, oid, format, src)View on GitHub (pinned to ec1a0befd2)