Diagnostic Queries
Symptoms
A text value being parsed as an array does not follow array-literal syntax. PostgreSQL raises SQLSTATE 22P02 (invalid_text_representation) and points to the parse failure.
- Array literals must be wrapped in braces:
{1,2,3}. - A DETAIL line explains what was expected (e.g.
“{”). - Common when passing a comma-separated string instead of an array literal.
What the server log shows
ERROR: malformed array literal: "1,2,3"
DETAIL: Array value must start with "{" or dimension information.
Why PostgreSQL raises this — what the manual says
Section 8.15.2 Array Value Input:
“To write an array value as a literal constant, enclose the element values within curly braces and separate them by commas.”
Array input expects brace-delimited, comma-separated elements with proper quoting/escaping. A bare comma-separated string lacks the braces and structure, so parsing fails with 22P02.
Common causes
- Passing
1,2,3instead of{1,2,3}. - Unquoted elements containing commas or special characters.
- Confusing SQL
ARRAY[…]syntax with the text literal form.
How to fix it
- Use the SQL constructor:
ARRAY[1,2,3]instead of a text literal. - If sending text, wrap in braces and quote elements as needed:
'{"a","b"}'. - Bind arrays via the driver’s array support rather than string concatenation.
Related & next steps
Reference: PostgreSQL 18 Section 8.15 “Arrays”.
Thanks — noted. This helps keep the database accurate.