22031
PostgreSQLERRORNotableData ExceptionHIGH confidence

invalid argument for SQL/JSON datetime function

What this means

SQLSTATE 22031 is raised when a SQL/JSON function receives an argument that does not fit the expected type or format for that specific function.

Why it happens
  1. 1SQL/JSON function receives an argument of the wrong type or outside the expected range
How to reproduce

SQL/JSON function with mismatched argument type.

expected output

ERROR:  invalid argument for SQL/JSON datetime function

Fix

Validate JSON values match expected types before applying SQL/JSON functions

WHEN When using SQL/JSON path functions on JSON documents.

Why this works

Use jsonb_typeof() to check the type of a JSON value before applying type-specific SQL/JSON functions.

Version notes
Postgres 15+

SQL/JSON support expanded in Postgres 15 and 16.

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