PostgreSQL raises SQLSTATE 22022 when an indicator variable is too small to store the length or NULL flag for a host variable in embedded SQL.
PostgreSQL indicator_overflow (SQLSTATE 22022) occurs when an indicator variable declared in embedded SQL is too small for the returned length or NULL status. Increase the indicator to a 32-bit or 64-bit integer in your host code to resolve the error.
PostgreSQL Error 22022 (indicator_overflow)
PostgreSQL emits SQLSTATE 22022 (indicator_overflow) when it cannot fit the result length or NULL flag of a host variable into the associated indicator variable during an embedded SQL operation. The server signals that the indicator variable lacks enough storage to represent the returned metadata.
The error appears during FETCH, SELECT INTO, or EXECUTE statements executed via ECPG, libpq, ODBC, or other interfaces that use indicator variables.
It rarely surfaces in plain psql sessions because indicator variables are only used in host-language bindings.
An indicator variable defined with a smaller integer type than required, such as using short instead of int, will overflow when PostgreSQL tries to write a large length value.
A mismatch between signed and unsigned types can also trigger the exception.
Redefine the indicator variable with a type large enough for any expected length or scale value. In C ECPG code, declare the indicator as int or long instead of short. Re-compile and run the application to verify the error disappears.
Bulk FETCH loops that retrieve text or bytea columns longer than 32,767 bytes frequently overflow a 16-bit indicator.
Switching to a 32-bit or 64-bit integer resolves the issue without touching database schema.
Always size indicator variables equal to or larger than the host variable length field defined by the interface specification. Review generated code from ORMs or code generators and override defaults that choose small integer types.
Errors such as SQLSTATE 22001 (string_data_right_truncation) or 22003 (numeric_value_out_of_range) may surface in similar data movement contexts.
The troubleshooting workflow is analogous: check variable sizes, type compatibility, and client encoding.
.
It is a client-side exception detected when PostgreSQL writes into the client-supplied indicator variable.
Yes. Adjust only the client code that declares the indicator variable.
No rows are written until the statement succeeds, so data remains unchanged.
Galaxy's type-aware editor surfaces host variable definitions and warns when indicator sizes are unsafe, reducing runtime surprises.