Diagnostic Queries
Symptoms
A string being cast to a range type was not formatted as a valid range literal. PostgreSQL raises SQLSTATE 22P02 (invalid_text_representation).
- The range literal’s syntax is invalid.
- Range literals need bound markers and a comma.
- Common with missing brackets/parentheses or comma.
What the server log shows
ERROR: malformed range literal: "[1 10]"
DETAIL: Missing comma after lower bound.
Why PostgreSQL raises this — what the manual says
Section 8.17 Range Types:
“Every non-empty range has two bounds, the lower bound and the upper bound.”
Range types parse a specific literal grammar: an inclusive/exclusive bound marker, lower bound, comma, upper bound, and closing marker. Input not matching that grammar can’t be parsed, so PostgreSQL reports 22P02 with a DETAIL explaining what’s wrong.
Common causes
- Missing comma between the bounds.
- Missing or mismatched brackets/parentheses.
- Extra characters or malformed bound values.
How to fix it
- Format as
'[1,10)'(inclusive lower, exclusive upper) or another valid form. - Use the range constructor:
int4range(1, 10). - Read the DETAIL line, which points to the exact syntax problem.
Related & next steps
Reference: PostgreSQL 18 Section 8.17 “Range Types”.
Thanks — noted. This helps keep the database accurate.