22036
PostgreSQLERRORNotableData ExceptionHIGH confidence

non-numeric SQL/JSON item

What this means

SQLSTATE 22036 is raised when a SQL/JSON arithmetic or numeric operation receives a non-numeric value (such as a string or boolean) from a JSON path expression.

Why it happens
  1. 1Applying arithmetic operators or numeric SQL/JSON functions to a JSON string or boolean value
How to reproduce

SQL/JSON arithmetic on a non-numeric JSON value.

trigger — this will error
trigger — this will error
SELECT jsonb_path_query('{"x":"hello"}'::jsonb, '$.x + 1');

expected output

ERROR:  operand of unary operator is not a numeric value

Fix

Ensure the JSON value is numeric before applying arithmetic

WHEN When performing math on JSON values.

Ensure the JSON value is numeric before applying arithmetic
SELECT jsonb_path_query('{"x":5}'::jsonb, '$.x + 1');

Why this works

Validate JSON schema so that numeric fields contain numbers, not strings.

Version notes
Postgres 14+

SQL/JSON arithmetic path operations available from Postgres 12+.

Sources
Official documentation ↗

Class 22 — Data Exception

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All PostgreSQL errors