jackc/pgx · error

is less than minimum value for uint8

Error message

%d is less than minimum value for uint8

What it means

scanPlanBinaryInt2ToUint8 decoded a negative int2 value; unsigned uint8 targets cannot hold negatives, so the value is rejected before conversion.

Solutions

  1. Scan into a signed Go type (int16/int32)
  2. Use abs() or constrain the column to non-negative values
Defensive patterns

Strategy: validation

When it happens

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

Appendix: source

Thrown at pgtype/int.go:346

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

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

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

	n := int16(raw)
	if n < 0 {
		return fmt.Errorf("%d is less than minimum value for uint8", n)
	}

	if n > math.MaxUint8 {
		return fmt.Errorf("%d is greater than maximum value for uint8", n)
	}

	*p = uint8(n)

	return nil
}

type scanPlanBinaryInt2ToInt16 struct{}

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

View on GitHub (pinned to ec1a0befd2)