Informix Error -9602: Illegal attempt to convert a collection type into another type.
Cause and resolution
Illegal attempt to convert a collection type into another type.
You attempted to store a collection of one type in a collection of a different type, or you attempted to move a collection into a host variable that is not a collection. In ESQL/C, a collection host variable declared to contain elements of a specific type can only hold collections of that same type. If you require that a collection host variable hold collections of different types, declare it without the specific type information.
Oninit® Troubleshooting Guidance
Reasons / Common Causes
-9602 fires when a collection is stored into a collection of a different element type, or into a host variable that isn't a collection at all — per the official guidance.
- Storing a collection of one type into a collection of a different type, per the official guidance — the first named cause.
- Moving a collection into a non-collection host variable, per the official guidance — the second named cause; in ESQL/C, a typed collection host variable can only hold collections of that same type.
Solutions / Resolution
- Declare the collection host variable without specific type information, per the official guidance, if it needs to hold collections of different types.
Examples
An ESQL/C collection type mismatch
EXEC SQL BEGIN DECLARE SECTION;
ifx_list_t *list_of_int;
EXEC SQL END DECLARE SECTION;
-- -9602 if a LIST(VARCHAR) is fetched into list_of_int
Corrected — declaring without specific element type
EXEC SQL BEGIN DECLARE SECTION;
ifx_collection_t *any_list;
EXEC SQL END DECLARE SECTION;
Diagnostic Checks
- Check the host variable's declared collection element type against the actual collection type being stored, and declare it untyped if it must hold multiple types.
Related Errors / Related Topics
- -9610 — "Illegal attempt to use collection host variable." A related collection- host-variable error, on cardinality/untyped-assignment/derived-table syntax rather than a type-conversion mismatch.
A collection was stored into an incompatible type or a non-collection host variable — declare the host variable untyped, or match the element type.