jackc/pgx · error
range upper bound cannot be NULL
Error message
range upper bound cannot be NULL
What it means
The binary range's upper bound is marked bounded by the flags byte, but its wire encoding is NULL (negative length prefix) — a contradiction between the flags and the payload. Symmetric to the lower-bound check.
Solutions
- Reject the malformed binary range value
- Ensure the encoder sets the unbounded flag instead of writing NULL for missing bounds
- Log the payload to trace which producer is inconsistent
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at pgtype/range.go:250 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/be87a4f3c5fbc490.
Report an issue: GitHub.
Appendix: source
Thrown at pgtype/range.go:250
ubr.UpperType = Inclusive
case rangeType&upperUnboundedMask > 0:
ubr.UpperType = Unbounded
default:
ubr.UpperType = Exclusive
}
if ubr.LowerType != Unbounded {
val, null := r.Value()
if null {
return nil, fmt.Errorf("range lower bound cannot be NULL")
}
ubr.Lower = val
}
if ubr.UpperType != Unbounded {
val, null := r.Value()
if null {
return nil, fmt.Errorf("range upper bound cannot be NULL")
}
ubr.Upper = val
}
if err := r.Finish(); err != nil {
return nil, fmt.Errorf("range: %w", err)
}
return ubr, nil
}
// Range is a generic range type.
type Range[T any] struct {
Lower T
Upper T
LowerType BoundType
UpperType BoundType
Valid boolView on GitHub (pinned to ec1a0befd2)