jackc/pgx · error
is out of range for int64
Error message
%v is out of range for int64
What it means
The binary numeric-to-int8 scan plan first decodes the value to a Numeric, reduces it to a big.Int, then bounds-checks it. This guard fires at that final check: the numeric value decoded fine but its integer magnitude exceeds the int64 range, so it cannot be stored in the Int8 destination.
Solutions
- Scan into pgtype.Numeric instead of *int64/int8
- Constrain or clamp values in the query (e.g. with least/greatest) before scanning
- Check the column's numeric precision for out-of-range stored data
Defensive patterns
Strategy: type-guard
When it happens
Trigger: Thrown at pgtype/numeric.go:776 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/473a2a7373df22df.
Report an issue: GitHub.
Appendix: source
Thrown at pgtype/numeric.go:776
if src == nil {
return scanner.ScanInt64(Int8{})
}
var n Numeric
err := scanPlanBinaryNumericToNumericScanner{}.Scan(src, &n)
if err != nil {
return err
}
bigInt, err := n.toBigInt()
if err != nil {
return err
}
if !bigInt.IsInt64() {
return fmt.Errorf("%v is out of range for int64", bigInt)
}
return scanner.ScanInt64(Int8{Int64: bigInt.Int64(), Valid: true})
}
type scanPlanBinaryNumericToTextScanner struct{}
func (scanPlanBinaryNumericToTextScanner) Scan(src []byte, dst any) error {
scanner := (dst).(TextScanner)
if src == nil {
return scanner.ScanText(Text{})
}
var n Numeric
err := scanPlanBinaryNumericToNumericScanner{}.Scan(src, &n)
if err != nil {View on GitHub (pinned to ec1a0befd2)