jackc/pgx · error

Lower cannot be NULL unless LowerType is Unbounded

Error message

Lower cannot be NULL unless LowerType is Unbounded

What it means

The range's lower bound is marked bounded (Inclusive or Exclusive) but the bound value returned by the RangeValuer is nil. The binary format cannot encode a NULL for a bounded bound, so this is an inconsistent value state supplied by the caller.

Solutions

  1. Set LowerType to Unbounded when the lower value is absent
  2. Provide a non-nil lower bound value for bounded ranges
  3. Use pgtype.Range[T] whose Valid/bound-type invariants prevent this
Defensive patterns

Strategy: validation

When it happens

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

Appendix: source

Thrown at pgtype/range_codec.go:110

	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")
		}

		sp := len(buf)
		buf = pgio.AppendInt32(buf, -1)

		lowerPlan := plan.m.PlanEncode(plan.rc.ElementType.OID, BinaryFormatCode, 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)