PostgreSQL Array Literal Builder and Parser
Turn a list of values or a JSON array into a correctly quoted PostgreSQL array literal and the equivalent ARRAY[...] constructor, ready for INSERT, = ANY() and && queries. Elements with spaces, commas, quotes, backslashes, braces or the word NULL are quoted exactly the way Postgres does it. Switch to Parse mode to paste an existing '{...}' value: the tool splits it into elements, shows it as JSON, and reports the same malformed array literal details Postgres would. Everything runs in your browser.
Do more than postgresql array literal builder and parser — meet Chat2DB
Chat2DB is an AI-powered SQL client for Windows, macOS and Linux. Write SQL in natural language, format and optimize queries automatically, and manage MySQL, PostgreSQL, Oracle and 20+ other databases in one workspace.
How to use
- Pick Build or Parse mode and the element type (text, integer, uuid, jsonb and so on).
- In Build mode, paste one value per line or a JSON array (nested arrays become multidimensional); in Parse mode, paste a '{...}' literal.
- Click Run to get the quoted literal, ARRAY constructor and example SQL, or the parsed elements and any error details.
Frequently asked questions
How do I write a PostgreSQL array literal?
Wrap the elements in braces and separate them with commas, for example '{1,2,3}' or '{red,green}'. Put double quotes around any element that is empty, contains a comma, space, brace, double quote or backslash, or is the word NULL you want as text; inside quotes, escape " and \ with a backslash. An unquoted NULL is a SQL NULL.
What causes "malformed array literal" in Postgres?
The input string is not in array syntax. Common causes are passing a JSON array like [1,2] or a bare comma list like 1,2 where Postgres expects '{1,2}', unbalanced quotes or braces, a trailing comma, and sub-arrays of different lengths. The DETAIL line tells you which rule failed; this tool reproduces it.
Can I run and test array queries without the command line?
Yes. Chat2DB connects to PostgreSQL, runs queries with array columns and shows the results in a grid, and its AI assistant can write ANY(), unnest() and array_agg() queries from a plain-English prompt. Get it at chat2db.ai/download or open the web version.
