jackc/pgx · error
cannot scan into from range element
Error message
cannot scan into %v from range element
What it means
The TypeMap has no scan plan for decoding the range's lower bound element into the target the RangeScanner exposed via ScanBounds — the Go target type does not match the range's element type. This is a plan lookup failure, not malformed data.
Solutions
- Register a scan codec for the element type, or scan into a compatible Go type
- Ensure the destination struct's bound fields match the column's range element type
- Use pgtype.Range[T] with T matching the element for automatic planning
Defensive patterns
Strategy: type-guard
When it happens
Trigger: Thrown at pgtype/range_codec.go:278 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/c9f04dae73528b4e.
Report an issue: GitHub.
Appendix: source
Thrown at pgtype/range_codec.go:278
if src == nil {
return rangeScanner.ScanNull()
}
ubr, err := parseUntypedBinaryRange(src)
if err != nil {
return err
}
if ubr.LowerType == Empty {
return rangeScanner.SetBoundTypes(ubr.LowerType, ubr.UpperType)
}
lowerTarget, upperTarget := rangeScanner.ScanBounds()
if ubr.LowerType == Inclusive || ubr.LowerType == Exclusive {
lowerPlan := plan.m.PlanScan(plan.rc.ElementType.OID, BinaryFormatCode, lowerTarget)
if lowerPlan == nil {
return fmt.Errorf("cannot scan into %v from range element", lowerTarget)
}
err = lowerPlan.Scan(ubr.Lower, lowerTarget)
if err != nil {
return fmt.Errorf("cannot scan into %v from range element: %w", lowerTarget, err)
}
}
if ubr.UpperType == Inclusive || ubr.UpperType == Exclusive {
upperPlan := plan.m.PlanScan(plan.rc.ElementType.OID, BinaryFormatCode, upperTarget)
if upperPlan == nil {
return fmt.Errorf("cannot scan into %v from range element", upperTarget)
}
err = upperPlan.Scan(ubr.Upper, upperTarget)
if err != nil {
return fmt.Errorf("cannot scan into %v from range element: %w", upperTarget, err)
}View on GitHub (pinned to ec1a0befd2)