42P22ERRORTier 2 — Caution✅ HIGH confidenceindeterminate datatype
Category: Syntax Error or Access Rule ViolationVersions: All Postgres versions
What this means
SQLSTATE 42P22 is a Postgres-specific error raised when Postgres cannot determine the data type of an expression — typically an untyped literal or parameter — from the context.
Why it happens
- 1A bare untyped literal (e.g., NULL without a cast) in a context where Postgres cannot infer the type
- 2An untyped parameter ($1) in a prepared statement where the type cannot be inferred from context
How to reproduce
SELECT with an untyped NULL in a function argument.
trigger — this will ERROR
SELECT * FROM some_function(NULL); -- which NULL type?ERROR: could not determine data type of parameter $1
Fix 1: Cast the untyped literal or parameter to the expected type
When an untyped literal causes type inference to fail.
fix
SELECT * FROM some_function(NULL::TEXT);
-- or for prepared statement parameters:
-- PREPARE stmt (TEXT) AS SELECT * FROM some_function($1);Why this works
Explicit type casting removes the ambiguity by telling Postgres exactly what type the expression is.
Sources
📚 Official docs: https://www.postgresql.org/docs/current/errcodes-appendix.html
🔧 Source ref: Class 42 — Syntax Error or Access Rule Violation (Postgres-specific)
Confidence assessment
✅ HIGH confidence
Postgres-specific. Stable across versions.
See also
📄 Reference pages
Type CastingPREPAREType Inference
⚙️ 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 →