jackc/pgx · error

numeric

Error message

numeric: %w

What it means

After all digit groups of a binary numeric are consumed, the plan requires the reader to be exactly at the end of the payload. This wrapper fires when pgio's Finish reports leftover bytes — the value's length exceeds what its header-described digits account for, indicating a malformed or padded binary numeric.

Solutions

  1. Verify the binary numeric value has no extra trailing bytes
  2. Use text format for numeric columns
  3. Report as a driver bug if the value came from the server
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at pgtype/numeric.go:685 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/3ca26b91e46d461e. Report an issue: GitHub.

Appendix: source

Thrown at pgtype/numeric.go:685

			case 1:
				mul = bigNBase
			case 2:
				mul = bigNBaseX2
			case 3:
				mul = bigNBaseX3
			case 4:
				mul = bigNBaseX4
			default:
				return fmt.Errorf("invalid digitsRead: %d (this can't happen)", digitsRead)
			}
			accum.Mul(accum, mul)
		}

		accum.Add(accum, big.NewInt(int64accum))
	}

	if err := r.Finish(); err != nil {
		return fmt.Errorf("numeric: %w", err)
	}

	exp := (int32(weight) - int32(ndigits) + 1) * 4

	if dscale > 0 {
		fracNBaseDigits := int(ndigits) - int(weight) - 1
		fracDecimalDigits := fracNBaseDigits * 4
		dscaleInt := int(dscale)

		if dscaleInt > fracDecimalDigits {
			multCount := dscaleInt - fracDecimalDigits
			for range multCount {
				accum.Mul(accum, big10)
				exp--
			}
		} else if dscaleInt < fracDecimalDigits {
			divCount := fracDecimalDigits - dscaleInt
			for range divCount {

View on GitHub (pinned to ec1a0befd2)