22030ERRORTier 2 — Caution✅ HIGH confidenceinvalid argument for SQL/JSON datetime function
Category: Data ExceptionVersions: Postgres 15+
What this means
SQLSTATE 22030 is raised when a SQL/JSON datetime function receives an argument that is not a valid datetime value in the expected format.
Why it happens
- 1Passing a JSON string that is not a valid ISO 8601 datetime to a SQL/JSON datetime extraction function
How to reproduce
SQL/JSON datetime function with invalid input.
trigger — this will ERROR
SELECT jsonb_path_query('{"d":"not-a-date"}'::jsonb, '$.d.datetime()');ERROR: datetime format is not recognized: "not-a-date"
Fix 1: Ensure JSON datetime strings use ISO 8601 format
When using SQL/JSON datetime functions.
fix
SELECT jsonb_path_query('{"d":"2024-01-15T10:30:00Z"}'::jsonb, '$.d.datetime()');Why this works
SQL/JSON datetime functions expect ISO 8601 formatted strings. Validate and normalise datetime strings before storing in JSON.
Version notes
Postgres 15+SQL/JSON path functions with datetime support introduced in Postgres 15.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 datetime validation. Available from Postgres 15.
See also
📄 Reference pages
SQL/JSON Path Languagejsonb_path_query
⚙️ 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 →