jackc/pgx · error

unknown lower bound type

Error message

unknown lower bound type %v

What it means

While choosing the opening bracket for the text range representation, LowerType is not Exclusive, Unbounded, Inclusive, or Empty — an out-of-enum BoundType. Only values from the defined constants are renderable in text syntax.

Solutions

  1. Use only the pgtype BoundType constants for LowerType
  2. Never construct BoundType from raw integers
  3. Reset range values instead of reusing stale struct memory
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at pgtype/range_codec.go:182 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/06e6279c5dcf8522. Report an issue: GitHub.

Appendix: source

Thrown at pgtype/range_codec.go:182

func (plan *encodePlanRangeCodecRangeValuerToText) Encode(value any, buf []byte) (newBuf []byte, err error) {
	getter := value.(RangeValuer)

	if getter.IsNull() {
		return nil, nil
	}

	lowerType, upperType := getter.BoundTypes()
	lower, upper := getter.Bounds()

	switch lowerType {
	case Exclusive, Unbounded:
		buf = append(buf, '(')
	case Inclusive:
		buf = append(buf, '[')
	case Empty:
		return append(buf, "empty"...), nil
	default:
		return nil, fmt.Errorf("unknown lower bound type %v", lowerType)
	}

	if lowerType != Unbounded {
		if lower == nil {
			return nil, fmt.Errorf("Lower cannot be NULL unless LowerType is Unbounded")
		}

		lowerPlan := plan.m.PlanEncode(plan.rc.ElementType.OID, TextFormatCode, lower)
		if lowerPlan == nil {
			return nil, fmt.Errorf("cannot encode %v as element of range", lower)
		}

		buf, err = lowerPlan.Encode(lower, buf)
		if err != nil {
			return nil, fmt.Errorf("failed to encode %v as element of range: %w", lower, err)
		}
		if buf == nil {
			return nil, fmt.Errorf("Lower cannot be NULL unless LowerType is Unbounded")

View on GitHub (pinned to ec1a0befd2)