jackc/pgx · error

is greater than maximum value for int64

Error message

%f is greater than maximum value for int64

What it means

Returned by float32Wrapper.Int64Value when the wrapped float32 value is greater than math.MaxInt64 and therefore cannot be converted to an Int8 for encoding. Integer conversion of such a large float is undefined in Go.

Solutions

  1. Store the value in a float column (float4/float8) instead of an integer column
  2. Clamp or reject values exceeding int64 range before encoding
  3. Use pgtype.Float8 which never converts to int internally
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at pgtype/builtin_wrappers.go:325 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/cb86fa9b2abfcec1. Report an issue: GitHub.

Appendix: source

Thrown at pgtype/builtin_wrappers.go:325

}

type float32Wrapper float32

func (w float32Wrapper) SkipUnderlyingTypePlan() {}

func (w *float32Wrapper) ScanInt64(v Int8) error {
	if !v.Valid {
		return fmt.Errorf("cannot scan NULL into *float32")
	}

	*w = float32Wrapper(v.Int64)

	return nil
}

func (w float32Wrapper) Int64Value() (Int8, error) {
	if w > math.MaxInt64 {
		return Int8{}, fmt.Errorf("%f is greater than maximum value for int64", w)
	}

	return Int8{Int64: int64(w), Valid: true}, nil
}

func (w *float32Wrapper) ScanFloat64(v Float8) error {
	if !v.Valid {
		return fmt.Errorf("cannot scan NULL into *float32")
	}

	*w = float32Wrapper(v.Float64)

	return nil
}

func (w float32Wrapper) Float64Value() (Float8, error) {
	return Float8{Float64: float64(w), Valid: true}, nil
}

View on GitHub (pinned to ec1a0befd2)