Diagnostic Queries
Symptoms
A string being cast to an array type was not formatted as a valid array literal. PostgreSQL raises SQLSTATE 22P02 (invalid_text_representation).
- The array literal does not begin with a brace.
- Array literals are enclosed in curly braces.
- Common when passing comma-separated text without braces.
What the server log shows
ERROR: array value must start with "{" or dimension information
LINE 1: SELECT '''1,2,3'''::int[];
Why PostgreSQL raises this — what the manual says
Section 8.15.2 Array Value Input:
“To represent arrays with other lower bounds, the array subscript ranges can be specified explicitly before writing the array contents.”
PostgreSQL parses array literals from a brace-enclosed grammar like '{1,2,3}' (optionally with a leading dimension spec). Input that doesn’t start with { or a dimension clause isn’t a valid array literal, so PostgreSQL reports 22P02.
Common causes
- Passing
'1,2,3'instead of'{1,2,3}'. - Omitting the curly braces around array elements.
- Building the literal in application code without the brace syntax.
How to fix it
- Format the literal with braces:
'{1,2,3}'::int[]. - Use the
ARRAY[…]constructor:ARRAY[1,2,3]. - Quote string elements and escape special characters inside the braces.
Related & next steps
Reference: PostgreSQL 18 Section 8.15 “Arrays”.
Thanks — noted. This helps keep the database accurate.