jackc/pgx · error

invalid lower bound

Error message

invalid lower bound: %w

What it means

Parsing a text-format range failed at the very first token: reading the opening bound rune returned an error (empty or whitespace-only input after the "empty" check). The wrapped error is the underlying buffer read failure, so the input never even reached the '(' or '[' bracket.

Solutions

  1. Check the range string is non-empty and not only whitespace
  2. Validate the value comes from PostgreSQL range output (e.g. "[1,10)", "empty")
  3. Reject arbitrary user input before passing it to range scanning
Defensive patterns

Strategy: validation

When it happens

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

Appendix: source

Thrown at pgtype/range.go:44

	LowerType BoundType
	UpperType BoundType
}

func parseUntypedTextRange(src string) (*untypedTextRange, error) {
	utr := &untypedTextRange{}
	if src == "empty" {
		utr.LowerType = Empty
		utr.UpperType = Empty
		return utr, nil
	}

	buf := bytes.NewBufferString(src)

	skipWhitespace(buf)

	r, _, err := buf.ReadRune()
	if err != nil {
		return nil, fmt.Errorf("invalid lower bound: %w", err)
	}
	switch r {
	case '(':
		utr.LowerType = Exclusive
	case '[':
		utr.LowerType = Inclusive
	default:
		return nil, fmt.Errorf("missing lower bound, instead got: %v", string(r))
	}

	r, _, err = buf.ReadRune()
	if err != nil {
		return nil, fmt.Errorf("invalid lower value: %w", err)
	}
	buf.UnreadRune()

	if r == ',' {
		utr.LowerType = Unbounded

View on GitHub (pinned to ec1a0befd2)