How to fix Array value must start with "{" in PostgreSQL

PostgreSQLBEGINNERMEDIUMUpdated Dec 29, 2025· 130 views

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.

Quick fix

Fixes Array value must start with "{"

-- 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[];
  1. Identify the array syntax error
  2. Use curly braces for PostgreSQL array literals
  3. Use the ARRAY constructor for clarity
  4. Fix application code that constructs arrays
postgresql — error
-- 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[];
Array value must start with "{"

What this error means

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.

Typical symptoms

  • INSERT or UPDATE statements fail when trying to store array values
  • Cast operations like `'[1, 2, 3]'::integer[]` produce the error
  • Using JavaScript array syntax [item1, item2] causes parsing failure
  • Application-generated arrays fail when passed to PostgreSQL
  • Error message specifies the exact position where parsing failed

Common causes

  1. Using square brackets [] instead of curly braces {} in array literals
  2. Missing the opening curly brace in array syntax
  3. Application code (Node.js, Python, etc.) formatting arrays as JSON instead of PostgreSQL arrays
  4. Manually constructing array strings without proper formatting
  5. Attempting to cast an incorrectly formatted string to an array type

How to fix "Array value must start with "{""

1Identify the array syntax error

Check if your array value uses square brackets or lacks proper formatting:

sql
-- 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[];
2Use curly braces for PostgreSQL array literals

Replace square brackets with curly braces. Each element must be separated by a comma:

sql
-- 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.

3Use the ARRAY constructor for clarity

For complex values or when building arrays dynamically, use the ARRAY[] constructor. This is often simpler and avoids quoting issues:

sql
-- 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.

4Fix application code that constructs arrays

If your application (Node.js, Python, etc.) constructs array values, ensure it uses PostgreSQL syntax, not JSON:

javascript
// 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
# 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 arrays
5Handle special characters in array elements

When array elements contain spaces, commas, or special characters, they must be double-quoted:

sql
-- 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.

Advanced notes

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.

Frequently asked questions

What does "Array value must start with "{"" mean?
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.
How do I fix "Array value must start with "{""?
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.
What causes "Array value must start with "{""?
Using square brackets [] instead of curly braces {} in array literals Missing the opening curly brace in array syntax Application code (Node.js, Python, etc.) formatting arrays as JSON instead of PostgreSQL arrays
Is the "Array value must start with "{"" error serious?
It is a medium-severity error — more of a blocker than a risk. The steps above resolve it.

Official resources & further reading