SQLSTATE 22P02 ERROR Class 22: Data Exception

invalid_text_representation malformed array literal: “…” — 22P02

PostgreSQL error "malformed array 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 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,3 instead of {1,2,3}.
  • Unquoted elements containing commas or special characters.
  • Confusing SQL ARRAY[…] syntax with the text literal form.

How to fix it

  1. Use the SQL constructor: ARRAY[1,2,3] instead of a text literal.
  2. If sending text, wrap in braces and quote elements as needed: '{"a","b"}'.
  3. Bind arrays via the driver’s array support rather than string concatenation.

Related & next steps

Reference: PostgreSQL 18 Section 8.15 “Arrays”.

Was this helpful?