jackc/pgx · error
unknown upper bound type
Error message
unknown upper bound type %v
What it means
While choosing the closing bracket for the text range representation, UpperType is not Exclusive, Unbounded, or Inclusive (Empty returns earlier). The bound type cannot be mapped to ')' or ']', so text rendering is impossible.
Solutions
- Assign UpperType from the defined BoundType constants
- Validate enum state before encoding a range to text
- Avoid deserializing BoundType from untrusted numeric values
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at pgtype/range_codec.go:231 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/b7a448d4a13b1fe4.
Report an issue: GitHub.
Appendix: source
Thrown at pgtype/range_codec.go:231
return nil, fmt.Errorf("cannot encode %v as element of range", upper)
}
buf, err = upperPlan.Encode(upper, buf)
if err != nil {
return nil, fmt.Errorf("failed to encode %v as element of range: %w", upper, err)
}
if buf == nil {
return nil, fmt.Errorf("Upper cannot be NULL unless UpperType is Unbounded")
}
}
switch upperType {
case Exclusive, Unbounded:
buf = append(buf, ')')
case Inclusive:
buf = append(buf, ']')
default:
return nil, fmt.Errorf("unknown upper bound type %v", upperType)
}
return buf, nil
}
func (c *RangeCodec) PlanScan(m *Map, oid uint32, format int16, target any) ScanPlan {
switch format {
case BinaryFormatCode:
if _, ok := target.(RangeScanner); ok {
return &scanPlanBinaryRangeToRangeScanner{rc: c, m: m}
}
case TextFormatCode:
if _, ok := target.(RangeScanner); ok {
return &scanPlanTextRangeToRangeScanner{rc: c, m: m}
}
}
return nilView on GitHub (pinned to ec1a0befd2)