Error 22002 occurs when a NULL value is supplied without an indicator parameter in PostgreSQL embedded or parameterized SQL.
PostgreSQL Error 22002 (null_value_no_indicator_parameter) means the query tried to pass or fetch a NULL without providing an indicator variable. Add an indicator parameter, send the value as NULL using the binary protocol, or rewrite the query to avoid NULLs to resolve the issue.
PostgreSQL Error 22002
Error 22002 signals that PostgreSQL received or returned a NULL value but did not get the required indicator parameter telling it the value is NULL.
The condition mostly appears in embedded SQL (ECPG), libpq binary-protocol calls, or when using server-side prepared statements from drivers like ODBC/JDBC.
The driver sends a host variable’s data without marking it as NULL, so PostgreSQL cannot determine whether the value is NULL or just empty.
Using EXECUTE or FETCH in Embedded C without an accompanying indicator variable is the classic trigger.
Always pass a separate indicator parameter and set it to -1 to flag NULL.
In libpq, send a NULL pointer for the value and a length of 0.
Rewrite queries so that NOT NULL columns never receive NULL input.
Validate data before binding.
ODBC Application - Bind SQL_NULL_DATA for the column to avoid the error.
ECPG Program - Add an int indicator variable after each nullable host variable.
Standardize data-access layers so every nullable column has a clear indicator path.
Use Galaxy collections to store tested parameterized queries so teammates reuse safe patterns.
22004 (null_value_not_allowed) happens when a NULL hits a NOT NULL column; supply a real value instead.
22001 (string_data_right_truncation) occurs when data exceeds column size; trim or widen the column.
.
Mostly client side. The server merely reports the missing indicator; fix your driver or embedded code.
No. It surfaces in APIs that use host variables or binary protocols, not plain SQL entered in psql.
Galaxy’s AI copilot flags queries where nullable columns lack explicit NULL handling, reducing risk.
A default value avoids sending NULL altogether, which prevents the error, but only if the default is acceptable to your logic.