22002ERRORTier 3 — Handle with care✅ HIGH confidencenull 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.
Fix 1: Declare and use an indicator variable for nullable columns in ECPG
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 docs: https://www.postgresql.org/docs/current/errcodes-appendix.html
🔧 Source ref: Class 22 — Data Exception
Confidence assessment
✅ HIGH confidence
Standard SQLSTATE primarily relevant to ECPG embedded SQL. Rarely seen in application-level code.
See also
📄 Reference pages