DBAtlas · Database operations atlas

22004: null_value_not_allowed

PostgreSQL

What does it mean?

A NULL was passed where NULL is not accepted. This differs from a column NOT NULL constraint (23502); it usually comes from passing NULL to a parameter or operation that does not accept NULL in a function or procedure context. Belongs to Class 22 (data_exception).

Why does it happen?

Assigning NULL to a PL/pgSQL variable declared NOT NULL; passing a NULL query string to EXECUTE; or passing NULL to built-in function arguments that do not accept it. Note: a function marked STRICT does not raise an error on NULL input — it returns NULL without executing.

How to fix it

Find the failing line (CONTEXT) and guard the value reaching it with a NULL check, or supply a default with COALESCE: COALESCE(value, default_value). In PL/pgSQL, validate values before assigning them to NOT NULL variables; in dynamic SQL make sure the string passed to EXECUTE is not NULL. Prevent mandatory fields from being sent as NULL at the application layer.

Open in DBAtlas →

More from this engine