42P22
PostgreSQLERRORNotableSyntax Error or Access Rule ViolationHIGH confidence

indeterminate datatype

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
  1. 1A bare untyped literal (e.g., NULL without a cast) in a context where Postgres cannot infer the type
  2. 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
trigger — this will error
SELECT * FROM some_function(NULL); -- which NULL type?

expected output

ERROR:  could not determine data type of parameter $1

Fix

Cast the untyped literal or parameter to the expected type

WHEN When an untyped literal causes type inference to fail.

Cast the untyped literal or parameter to the expected type
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 documentation ↗

Class 42 — Syntax Error or Access Rule Violation (Postgres-specific)

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All PostgreSQL errors