Common SQL Errors

Fixing PostgreSQL indicator_overflow Error (SQLSTATE 22022)

August 4, 2025

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.

Sign up for the latest in common SQL errors from the Galaxy Team!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

What is the indicator_overflow error?

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.

Error Highlights

Typical Error Message

PostgreSQL Error 22022 (indicator_overflow)

Error Type

Data Conversion Error

Language

PostgreSQL

Symbol

indicator_overflow

Error Code

22022

SQL State

Explanation

Table of Contents

What does the indicator_overflow error mean?

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.

When does PostgreSQL raise SQLSTATE 22022?

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.

What Causes This Error?

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.

How to Fix indicator_overflow

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.

Common Scenarios and Solutions

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.

Best Practices to Avoid This Error

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.

Related Errors and Solutions

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.

.

Common Causes

Related Errors

FAQs

Is indicator_overflow a server or client error?

It is a client-side exception detected when PostgreSQL writes into the client-supplied indicator variable.

Can I fix this without changing the database?

Yes. Adjust only the client code that declares the indicator variable.

Does the error affect data integrity?

No rows are written until the statement succeeds, so data remains unchanged.

How does Galaxy help prevent this error?

Galaxy's type-aware editor surfaces host variable definitions and warns when indicator sizes are unsafe, reducing runtime surprises.

Start Querying with the Modern SQL Editor Today!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

Check out some other errors

Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie Logo
Bauhealth Logo
Truvideo Logo