SQLSTATE 22P02 ERROR Class 22: Data Exception

invalid_text_representation malformed range literal: “…” — 22P02

PostgreSQL error "malformed range literal: "…"" (SQLSTATE 22P02): what it means, common causes, and how to fix it.

PG 12, 13, 14, 15, 16, 17, 18 Official docs
Last reviewed May 2025 Grounded in source

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

  1. Format as '[1,10)' (inclusive lower, exclusive upper) or another valid form.
  2. Use the range constructor: int4range(1, 10).
  3. Read the DETAIL line, which points to the exact syntax problem.

Related & next steps

Reference: PostgreSQL 18 Section 8.17 “Range Types”.

Was this helpful?