PostgreSQL requires array literals to start with a curly brace {}. This error occurs when you use incorrect syntax like square brackets [] or omit the opening brace entirely. Fix it by using proper PostgreSQL array syntax or the ARRAY constructor.
PostgreSQL arrays have a specific syntax that requires values to be enclosed in curly braces {}. When PostgreSQL attempts to parse a value as an array and encounters something that does not start with the required opening brace, it raises this error. This typically happens when: 1. You use JavaScript/JSON-style square brackets [] instead of curly braces {} 2. The value is missing the opening curly brace entirely 3. The application layer formats arrays incorrectly before sending to PostgreSQL 4. A string is being cast to an array type without proper formatting Understanding this error is important because PostgreSQL is strict about array syntax—it will not automatically convert between different bracket styles like some other databases might.
Check if your array value uses square brackets or lacks proper formatting:
-- WRONG: Square brackets
SELECT '[1, 2, 3]'::integer[]; -- Error
INSERT INTO table (arr_col) VALUES (['a', 'b']);
-- WRONG: Missing opening brace
SELECT '1, 2, 3}'::integer[];Replace square brackets with curly braces. Each element must be separated by a comma:
-- CORRECT: Curly braces
SELECT '{1, 2, 3}'::integer[];
SELECT '{"apple", "banana", "cherry"}'::text[];
SELECT '{1.5, 2.5, 3.5}'::float8[];Note the outer single quotes wrapping the entire array literal.
For complex values or when building arrays dynamically, use the ARRAY[] constructor. This is often simpler and avoids quoting issues:
-- Using ARRAY constructor
SELECT ARRAY[1, 2, 3]::integer[];
SELECT ARRAY['apple', 'banana', 'cherry']::text[];
SELECT ARRAY[TRUE, FALSE, TRUE]::boolean[];The ARRAY constructor automatically handles type casting and is recommended for most use cases.
If your application (Node.js, Python, etc.) constructs array values, ensure it uses PostgreSQL syntax, not JSON:
// Node.js / JavaScript - WRONG
const arr = [1, 2, 3]; // This is JSON
const query = `INSERT INTO users (ids) VALUES (${arr})`; // Will fail
// Node.js / JavaScript - CORRECT
const arr = [1, 2, 3];
const pgArray = '{" + arr.join(", ") + "}';
const query = `INSERT INTO users (ids) VALUES ('${pgArray}'::integer[])`;
// Better: Let parameterized queries handle it
const query = 'INSERT INTO users (ids) VALUES ($1)';
await db.query(query, [arr]); // Driver converts array automatically# Python - WRONG
arr = [1, 2, 3]
cursor.execute("INSERT INTO users (ids) VALUES (%s)", (arr,))
# Python - CORRECT with psycopg2
from psycopg2.extras import execute_values
arr = [1, 2, 3]
cursor.execute("INSERT INTO users (ids) VALUES (%s)", (arr,))
# psycopg2 automatically converts Python lists to PostgreSQL arraysWhen array elements contain spaces, commas, or special characters, they must be double-quoted:
-- Elements with spaces need double quotes
SELECT '{"hello world", "another value", "test"}'::text[];
-- Elements with commas must be quoted
SELECT '{"value, with comma", "normal"}'::text[];
-- Elements with double quotes need escaping
SELECT '{"value with \"quotes\"", "normal"}'::text[];When in doubt, quote all string elements using double quotes.
PostgreSQL Array Syntax Deep Dive: PostgreSQL uses Postgres-specific syntax for arrays, which differs from JSON. The distinction is important: JSON uses square brackets and is parsed by the jsonb/json types, while PostgreSQL arrays use curly braces. Most PostgreSQL client libraries (psycopg2, node-postgres, pg-promise) automatically convert native array types (Python lists, JavaScript arrays) to PostgreSQL format when using parameterized queries, so you typically do not need to manually format arrays in application code. However, if you are constructing raw SQL strings or working with array_agg(), array_literal functions, you must use proper PostgreSQL syntax. For multidimensional arrays, the syntax extends naturally: '{1,2},{3,4}' represents a 2x2 integer array. Empty arrays are represented as '{}'. The ARRAY constructor is particularly useful in triggers and stored procedures where clarity matters.
0LP01: invalid_grant_operation
How to fix "Invalid grant operation" (0LP01) in PostgreSQL
aggregate functions are not allowed in WHERE clause
How to fix "aggregate functions are not allowed in WHERE clause" in PostgreSQL
2200L: not_an_xml_document
How to fix "2200L: not_an_xml_document" in PostgreSQL
ERROR: ambiguous_parameter
42P08: Ambiguous parameter error
2201F: invalid_argument_for_power_function
Invalid argument for power function (2201F)