jackc/pgx · error

is greater than maximum value for int16

Error message

%d is greater than maximum value for int16

What it means

Range guard converting an int64 into Go int16: the source value exceeds math.MaxInt16 and would overflow, so the conversion is refused.

Solutions

  1. Use a wider scan target (int32/int64 or pgtype.Int8)
  2. Cast or constrain the column to int2 range in SQL
Defensive patterns

Strategy: validation

When it happens

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

Appendix: source

Thrown at pgtype/builtin_wrappers.go:51

func (w int8Wrapper) Int64Value() (Int8, error) {
	return Int8{Int64: int64(w), Valid: true}, nil
}

type int16Wrapper int16

func (w int16Wrapper) SkipUnderlyingTypePlan() {}

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

	if v.Int64 < math.MinInt16 {
		return fmt.Errorf("%d is less than minimum value for int16", v.Int64)
	}
	if v.Int64 > math.MaxInt16 {
		return fmt.Errorf("%d is greater than maximum value for int16", v.Int64)
	}
	*w = int16Wrapper(v.Int64)

	return nil
}

func (w int16Wrapper) Int64Value() (Int8, error) {
	return Int8{Int64: int64(w), Valid: true}, nil
}

type int32Wrapper int32

func (w int32Wrapper) SkipUnderlyingTypePlan() {}

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

View on GitHub (pinned to ec1a0befd2)