jackc/pgx · error

range

Error message

range: %w

What it means

After reading the flags byte and both bound values, the pgio.Reader still has unread bytes (r.Finish() failed). A well-formed binary range consumes its buffer exactly, so trailing data means the payload is malformed.

Solutions

  1. Fail the scan and discard the partially decoded range
  2. Check for transport or codec layers appending bytes to binary values
  3. Capture the payload length to compare against expected size
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at pgtype/range.go:256 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/212414336b44b727. Report an issue: GitHub.

Appendix: source

Thrown at pgtype/range.go:256

	if ubr.LowerType != Unbounded {
		val, null := r.Value()
		if null {
			return nil, fmt.Errorf("range lower bound cannot be NULL")
		}
		ubr.Lower = val
	}

	if ubr.UpperType != Unbounded {
		val, null := r.Value()
		if null {
			return nil, fmt.Errorf("range upper bound cannot be NULL")
		}
		ubr.Upper = val
	}

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

	return ubr, nil
}

// Range is a generic range type.
type Range[T any] struct {
	Lower     T
	Upper     T
	LowerType BoundType
	UpperType BoundType
	Valid     bool
}

func (r Range[T]) IsNull() bool {
	return !r.Valid
}

View on GitHub (pinned to ec1a0befd2)