39004
PostgreSQLERRORNotableExternal Routine Invocation ExceptionHIGH confidence
null value not allowed
What this means
SQLSTATE 39004 is raised when an external routine declared STRICT returns NULL in a context where NULL is not allowed, or passes NULL to a STRICT function argument.
Why it happens
- 1An external function declared STRICT is called with a NULL argument (STRICT functions return NULL for any NULL argument without executing — 39004 is raised if this contract is violated)
How to reproduce
STRICT external function receiving a NULL argument explicitly.
expected output
ERROR: null value not allowed
Fix
Filter NULLs before calling STRICT functions
WHEN When calling STRICT external functions with nullable data.
Filter NULLs before calling STRICT functions
SELECT my_strict_fn(col) FROM data WHERE col IS NOT NULL;
Why this works
STRICT functions short-circuit on NULL inputs by convention, but filtering NULLs in SQL prevents the issue entirely.
Sources
Official documentation ↗
Class 39 — External Routine Invocation Exception
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev