PG
PRO
22002ERRORTier 3 — Handle with care✅ HIGH confidence

null value, no indicator parameter

Category: Data ExceptionVersions: All Postgres versions

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

  1. 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.

trigger — this will ERROR
ERROR: null value returned to application without indicator variable

Fix 1: Declare and use an indicator variable for nullable columns in ECPG

When writing embedded SQL programs that fetch nullable columns.

fix

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

ECPG — Embedded SQL in C
⚙️ This error reference was generated with AI assistance and reviewed for accuracy. Examples are provided to illustrate common scenarios and may not cover every case. Always test fixes in a development environment before applying to production. Spotted an error? Suggest a correction →