jackc/pgx · error

is less than minimum value for int16

Error message

%d is less than minimum value for int16

What it means

A valid int4 was decoded but its value is below math.MinInt16, so it cannot be stored in the *int16 destination. Range guard in scanPlanBinaryInt4ToInt16; the too-negative integer is the faulting input.

Solutions

  1. Scan into a wider Go type (int32/int64)
  2. Clamp or validate the value range in the query
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at pgtype/int.go:952 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/f8beab405fe21b23. Report an issue: GitHub.

Appendix: source

Thrown at pgtype/int.go:952

func (scanPlanBinaryInt4ToInt16) Scan(src []byte, dst any) error {
	if src == nil {
		return fmt.Errorf("cannot scan NULL into %T", dst)
	}

	raw, err := pgio.Uint32Exact(src)
	if err != nil {
		return fmt.Errorf("int4: %w", err)
	}

	p, ok := (dst).(*int16)
	if !ok {
		return ErrScanTargetTypeChanged
	}

	n := int32(raw)
	if n < math.MinInt16 {
		return fmt.Errorf("%d is less than minimum value for int16", n)
	} else if n > math.MaxInt16 {
		return fmt.Errorf("%d is greater than maximum value for int16", n)
	}

	*p = int16(n)

	return nil
}

type scanPlanBinaryInt4ToUint16 struct{}

func (scanPlanBinaryInt4ToUint16) Scan(src []byte, dst any) error {
	if src == nil {
		return fmt.Errorf("cannot scan NULL into %T", dst)
	}

	raw, err := pgio.Uint32Exact(src)
	if err != nil {

View on GitHub (pinned to ec1a0befd2)