22002
PostgreSQLERRORCriticalData ExceptionHIGH confidence
null value, no indicator parameter
What this means
SQLSTATE 22002 is raised in embedded SQL (ECPG) when a query returns a NULL value into a host variable that has no associated indicator variable to receive the NULL flag. Without an indicator, the program cannot represent a NULL result.
Why it happens
- 1In ECPG, fetching a NULL value from a column into a host variable that has no indicator variable declared
How to reproduce
ECPG program fetching a nullable column without an indicator variable.
expected output
ERROR: null value returned to application without indicator variable
Fix
Declare and use an indicator variable for nullable columns in ECPG
WHEN When writing embedded SQL programs that fetch nullable columns.
Why this works
In ECPG, declare an indicator variable (short ind;) and reference it in the FETCH or SELECT INTO statement. When ind = -1, the fetched value was NULL.
Sources
Official documentation ↗
Class 22 — Data Exception
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev