Common SQL Errors

How to Fix PostgreSQL Error - 22036 non_numeric_sql_json_item Error

August 4, 2025

PostgreSQL raises non_numeric_sql_json_item (SQLSTATE 22036) when a SQL/JSON query tries to treat a non-numeric JSON value as a number.

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 non_numeric_sql_json_item error?

non_numeric_sql_json_item appears when a SQL/JSON path or function expects a numeric value but finds a string, boolean, or null instead. Cast the JSON field to the correct type or validate the data before running the query to resolve the error.

Error Highlights

Typical Error Message

non_numeric_sql_json_item

Error Type

Data Type Error

Language

PostgreSQL

Symbol

non_numeric_sql_json_item

Error Code

22036

SQL State

Explanation

Table of Contents

What is the PostgreSQL non_numeric_sql_json_item error?

non_numeric_sql_json_item (SQLSTATE 22036) is thrown by PostgreSQL when SQL/JSON processing encounters a JSON item that is not numeric where a numeric value is required.

The error usually appears in JSON path queries, jsonb_path_query(), jsonb_path_exists(), or when casting JSON text to numeric types inside SQL expressions.

What Causes This Error?

A JSON string, boolean, object, or null is supplied where the SQL/JSON runtime needs a number, triggering SQLSTATE 22036.

Explicit casts like (jsonb_column ->> 'age')::int fail if the stored value is not purely digits.

Incorrect path filters such as $.items[?(@.price > 10)] cause the engine to compare non-numeric text to a number, producing the condition.

How to Fix non_numeric_sql_json_item

Validate that the JSON element is numeric before casting or filtering.

Use jsonb_typeof() or a JSON path type filter to guard the operation.

Coerce text to numeric safely with NULLIF and regular expressions, or clean the data upstream.

Replace invalid JSON values or default them to 0 to keep analytics queries running.

Common Scenarios and Solutions

Path filter comparison: add a type filter like ?(@.price.type() == "number" && @.price > 10).

Bad cast in SELECT: wrap with CASE WHEN (jsonb_column ->> 'age') ~ '^\d+$' THEN ...

END.

Aggregations on mixed data: create a generated column storing a numeric copy and index it for faster querying.

Best Practices to Avoid This Error

Enforce JSON schema at ingestion time to keep numeric fields numeric.

Use generated computed columns to materialize numeric values and attach CHECK constraints.

Include defensive type checks in all ad-hoc queries or rely on Galaxy’s AI copilot to suggest safe casts.

Related Errors and Solutions

invalid_json_text: raised when JSON input is malformed.

invalid_sql_json_number: occurs when a JSON number is out of range for the requested type.

jsonb_path_invalid_data_type: appears when a path step meets an unexpected data type.

.

Common Causes

Related Errors

FAQs

Does this error exist in PostgreSQL 11?

No. SQL/JSON and the 22036 code were introduced in PostgreSQL 12.

Is there a configuration flag to disable the check?

No. The error is part of SQL/JSON standard compliance and cannot be turned off.

Can I index JSON numbers to avoid runtime casts?

Yes. Use expression indexes on ((data ->> 'amount')::numeric) once the data is clean.

How does Galaxy help avoid 22036?

Galaxy’s editor warns when your query casts JSON text to numeric without a type guard, preventing deployment of broken SQL.

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