jackc/pgx · error

int2

Error message

int2: %w

What it means

scanPlanBinaryInt2ToInt8 wraps pgio.Uint16Exact: the binary int2 payload was not exactly 2 bytes, so it cannot be interpreted as an int2. The wrapped error details the size mismatch.

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:307 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/c480ccb9acd335d3. Report an issue: GitHub.

Appendix: source

Thrown at pgtype/int.go:307

	var n int16
	err := codecScan(c, m, oid, format, src, &n)
	if err != nil {
		return nil, err
	}
	return n, nil
}

type scanPlanBinaryInt2ToInt8 struct{}

func (scanPlanBinaryInt2ToInt8) 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("int2: %w", err)
	}

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

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

	*p = int8(n)

	return nil
}

View on GitHub (pinned to ec1a0befd2)