Common SQL Errors

PostgreSQL Error - 22034 more_than_one_sql_json_item error explained

August 4, 2025

The error occurs when a PostgreSQL SQL/JSON query expected a single JSON item but produced multiple items.

Sign up for the latest in common SQL errors from the Galaxy Team!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

What is the more_than_one_sql_json_item error in PostgreSQL?

more_than_one_sql_json_item appears when a SQL/JSON path expression in PostgreSQL returns more than one item where only one is allowed. Trim the path or wrap results in an array to ensure a single item is produced, then rerun the query.

Error Highlights

Typical Error Message

more_than_one_sql_json_item

Error Type

Data Exception

Language

PostgreSQL

Symbol

more_than_one_sql_json_item

Error Code

22034

SQL State

Explanation

Table of Contents

What is the more_than_one_sql_json_item error in PostgreSQL?

PostgreSQL raises SQLSTATE 22034 when a SQL/JSON constructor such as JSON_VALUE or JSON_QUERY executes with a clause that permits only one item but the evaluated path returns more than one element.

The error protects data integrity by enforcing the SQL-JSON rule that JSON scalars must be unambiguous.

Applications that ignore this check might store or display wrong information, so fixing it quickly is essential.

What Causes This Error?

JSON_VALUE with WITHOUT ARRAY WRAPPER expects exactly one scalar.

If the path matches two or more nodes PostgreSQL throws the error immediately.

JSON_QUERY with WITHOUT ARRAY WRAPPER SINGLE behaves similarly, failing when multiple JSON objects satisfy the path.

Implicit casting from JSON to text inside a SELECT list can surface the error when the path picks multiple values.

Queries generated by ORMs or AI agents often forget to limit paths, leading to multiple-item results.

How to Fix more_than_one_sql_json_item

First confirm how many items the path returns using JSON_QUERY with WITH ARRAY WRAPPER to inspect the full set.

Rewrite the JSON path to target a single node, or add a predicate that narrows matches to one element only.

If multiple items are valid, switch to JSON_QUERY WITH ARRAY WRAPPER or JSON_ARRAY to collect them safely.

Validate the fix by rerunning the query in Galaxy or psql; the error should disappear and results should be stable.

Common Scenarios and Solutions

Accessing an array element without specifying an index often returns many nodes.

Add [0] or another index to fetch exactly one.

Filtering on a non-unique attribute such as $.users[*].role?(@ == "admin") can yield several admins. Append an additional predicate like && $.id == 1.

Using JSON_VALUE on a path that may be absent returns NULL or error depending on STRICT/DEFAULT. Wrap it in COALESCE and use DEFAULT NULL ON EMPTY.

When grouping results, unintended duplicates can map to one cell.

Use DISTINCT ON or LIMIT 1 to force a single value.

Best Practices to Avoid This Error

Design JSON schemas with unique keys so path expressions naturally map to single nodes.

Always test new JSON paths with JSON_QUERY and WITH CONDITIONAL WRAPPER in Galaxy before putting them in production code.

Add CHECK constraints that validate jsonb_array_length() where singleton objects are expected.

Enable statement logging in staging so repeated SQLSTATE 22034 events surface during QA, not in production.

Related Errors and Solutions

SQLSTATE 22035 no_sql_json_item appears when the path returns zero items; supply DEFAULT ON EMPTY to avoid it.

SQLSTATE 22036 singleton_sql_json_item_required triggers when a scalar is required but an array is found; wrap the array or cast appropriately.

SQLSTATE 22037 invalid_sql_json_path_literal fires when the JSON path is malformed; correct the syntax or quote identifiers properly.

.

Common Causes

Related Errors

FAQs

Does this error affect jsonb data type?

Yes. SQL/JSON functions operate on json and jsonb alike, and singleton rules apply equally.

Can I disable the singleton check?

No. SQL-standard behavior is enforced. Use array wrappers or rewrite the path.

Will PostgreSQL versions before 15 raise this error?

No. SQL/JSON constructors were introduced in PostgreSQL 15. Earlier versions use different JSON functions.

How does Galaxy help prevent this?

Galaxy highlights SQLSTATE codes inline, previews JSON results, and suggests wrapping paths, reducing the chance of committing faulty queries.

Start Querying with the Modern SQL Editor Today!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

Check out some other errors

Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie Logo
Bauhealth Logo
Truvideo Logo