jackc/pgx · error

range too short

Error message

range too short: %v

What it means

parseUntypedBinaryRange could not even read the one-byte range flags header from the binary range value; the payload is shorter than a single byte. An empty or truncated binary range from the server is at fault.

Solutions

  1. Treat the value as corrupt binary data and fail the scan
  2. Verify the binary range payload was not truncated in transit
  3. Check that empty/NULL ranges are sent as SQL NULL, not as an empty byte slice
Defensive patterns

Strategy: validation

When it happens

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

Appendix: source

Thrown at pgtype/range.go:209

// 16 = (      = 10000
// 18 = [      = 10010
// 24 =        = 11000

const (
	emptyMask          = 1
	lowerInclusiveMask = 2
	upperInclusiveMask = 4
	lowerUnboundedMask = 8
	upperUnboundedMask = 16
)

func parseUntypedBinaryRange(src []byte) (*untypedBinaryRange, error) {
	ubr := &untypedBinaryRange{}
	r := pgio.NewReader(src)

	rangeType := r.Byte()
	if r.Err() != nil {
		return nil, fmt.Errorf("range too short: %v", len(src))
	}

	if rangeType&emptyMask > 0 {
		if err := r.Finish(); err != nil {
			return nil, fmt.Errorf("empty range: %w", err)
		}
		ubr.LowerType = Empty
		ubr.UpperType = Empty
		return ubr, nil
	}

	switch {
	case rangeType&lowerInclusiveMask > 0:
		ubr.LowerType = Inclusive
	case rangeType&lowerUnboundedMask > 0:
		ubr.LowerType = Unbounded
	default:
		ubr.LowerType = Exclusive

View on GitHub (pinned to ec1a0befd2)