22031ERRORTier 2 — Caution✅ HIGH confidenceinvalid argument for SQL/JSON datetime function
Category: Data ExceptionVersions: Postgres 15+
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
- 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.
trigger — this will ERROR
ERROR: invalid argument for SQL/JSON datetime function
Fix 1: Validate JSON values match expected types before applying SQL/JSON functions
When using SQL/JSON path functions on JSON documents.
fix
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 docs: https://www.postgresql.org/docs/current/errcodes-appendix.html
🔧 Source ref: Class 22 — Data Exception
Confidence assessment
✅ HIGH confidence
Standard SQLSTATE for SQL/JSON argument validation. Postgres 15+ feature.
See also
🔗 Related errors
📄 Reference pages
SQL/JSON Path Language
⚙️ This error reference was generated with AI assistance and reviewed for accuracy. Examples are provided to illustrate common scenarios and may not cover every case. Always test fixes in a development environment before applying to production. Spotted an error? Suggest a correction →