jackc/pgx · error

is greater than maximum value for uint

Error message

%d is greater than maximum value for uint

What it means

ScanInt64 on uintWrapper received a valid Int8 whose value exceeds the platform's maximum uint size (math.MaxUint). This fires on 32-bit platforms where uint is 32 bits; the source int64 value does not fit in the target uint.

Solutions

  1. Scan into *uint64 instead of *uint when on a 32-bit platform
  2. Restrict column values with a CHECK constraint to the 32-bit unsigned range
  3. Use pgtype.Uint8 which is platform-independent
Defensive patterns

Strategy: validation

When it happens

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

Appendix: source

Thrown at pgtype/builtin_wrappers.go:264

func (w uint64Wrapper) NumericValue() (Numeric, error) {
	return Numeric{Int: new(big.Int).SetUint64(uint64(w)), Valid: true}, nil
}

type uintWrapper uint

func (w uintWrapper) SkipUnderlyingTypePlan() {}

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

	if v.Int64 < 0 {
		return fmt.Errorf("%d is less than minimum value for uint64", v.Int64)
	}

	if uint64(v.Int64) > math.MaxUint {
		return fmt.Errorf("%d is greater than maximum value for uint", v.Int64)
	}

	*w = uintWrapper(v.Int64)

	return nil
}

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

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

func (w *uintWrapper) ScanNumeric(v Numeric) error {
	if !v.Valid {
		return fmt.Errorf("cannot scan NULL into *uint")

View on GitHub (pinned to ec1a0befd2)