jackc/pgx · error

unknown LowerType

Error message

unknown LowerType: %v

What it means

While building the binary range flags byte, the value's LowerType is not one of Inclusive, Unbounded, Exclusive, or Empty. This fires only for a corrupted or manually constructed BoundType outside the defined enum, since normal code cannot produce other values.

Solutions

  1. Ensure LowerType is set from the pgtype BoundType constants only
  2. Do not cast arbitrary integers to BoundType
  3. Re-initialize range values instead of reusing memory with stale fields
Defensive patterns

Strategy: validation

When it happens

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

Appendix: source

Thrown at pgtype/range_codec.go:93

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

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

	var rangeType byte
	switch lowerType {
	case Inclusive:
		rangeType |= lowerInclusiveMask
	case Unbounded:
		rangeType |= lowerUnboundedMask
	case Exclusive:
	case Empty:
		return append(buf, emptyMask), nil
	default:
		return nil, fmt.Errorf("unknown LowerType: %v", lowerType)
	}

	switch upperType {
	case Inclusive:
		rangeType |= upperInclusiveMask
	case Unbounded:
		rangeType |= upperUnboundedMask
	case Exclusive:
	default:
		return nil, fmt.Errorf("unknown UpperType: %v", upperType)
	}

	buf = append(buf, rangeType)

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

View on GitHub (pinned to ec1a0befd2)