jackc/pgx · error

uint2

Error message

uint2: %w

What it means

The binary uint2 source is not exactly 2 bytes; pgio.Uint16Exact failed (wrapped with %w). The truncated binary smallint payload from the server is at fault. (Note the message prefix says 'uint2', the unsigned scan plan for int2.)

Solutions

  1. Treat as protocol/data corruption — verify the column is smallint
  2. Check for driver/server version mismatch
Defensive patterns

Strategy: validation

When it happens

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

Appendix: source

Thrown at pgtype/int.go:336

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

	*p = int8(n)

	return nil
}

type scanPlanBinaryInt2ToUint8 struct{}

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)

View on GitHub (pinned to ec1a0befd2)