Error 2203B appears when a SQL/JSON path expects a numeric value but the targeted JSON item is not a valid number.
sql_json_number_not_found occurs in PostgreSQL when a SQL/JSON path, operator, or cast expects a numeric value and none is found. Verify the JSON field is numeric or add a safe CAST/COALESCE to supply a default number to resolve the error.
PostgreSQL Error 2203B (sql_json_number_not_found)
Error 2203B (condition name sql_json_number_not_found) signals that a SQL/JSON expression expected a number but located none. PostgreSQL raises it whenever jsonpath methods such as .number(), arithmetic on JSON data, or explicit ::numeric casts fail to retrieve a numeric element.
The error emerges during SELECT, UPDATE, INSERT, or CHECK-constraint evaluation that touches JSON or JSONB columns.
Because the server aborts the statement, downstream logic stops, so fixing it quickly is crucial for application stability.
A non-numeric JSON scalar (e.g., string "abc") matched by a path accessor triggers the exception.
PostgreSQL must either find a valid number or throw 2203B.
Using .number() or jsonpath arithmetic on an absent key returns the same error, as does casting text data pulled with ->> to integer/decimal when the text is not numeric.
First confirm the JSON element is truly numeric by selecting it separately. If not numeric, correct the source data.
If data may vary, use COALESCE, try_cast style CASE expressions, or jsonb_path_query_first with a default.
Supply a fallback numeric literal or filter the jsonpath with ? (@.type() == "number") before invoking .number(). These tactics guarantee a number is always produced, preventing the error.
Application logs stored as JSON often mix strings and numbers.
Wrap casts in safe CASE WHEN jsonb_typeof(col->'key')='number' THEN (col->>'key')::numeric ELSE 0 END to avoid crashes.
Analytics queries that sum metrics inside JSON should pre-filter: SELECT SUM((e.value).number()) FROM jsonb_path_query(data,'$.events[*] ? (@.value.type() == "number")') AS e(value);
Validate JSON payloads on ingest, storing numbers as numbers, not strings. Add CHECK constraints using jsonb_typeof().number() filters.
Employ Galaxy’s schema-aware autocomplete to spot non-numeric casts early.
Its inline result preview lets you confirm types before running heavy queries.
2203A sql_json_value_too_long arises when the numeric value exceeds precision; 2203C sql_json_member_not_found appears when a key is missing. All can be mitigated by defensive JSON validation and typed columns.
.
No. The error can occur with both json and jsonb data types because it is triggered by SQL/JSON processing, not storage format.
A column default helps for new rows but does not protect queries on existing bad data. Always validate during querying too.
Versions 15 and later introduce SQL/JSON features and the 2203B code. Earlier versions will not emit this specific condition code.
Use jsonb_path_query with an ERROR ON EMPTY FALSE clause or wrap casts in TRY_CAST pattern to return NULL when no number exists.