Informix Error -307
-307 Illegal subscript definition.
This statement refers to a substring of a character variable. The substring values (two numbers in square brackets) are incorrect. The first is less than zero or greater than the length of the column, or the second is less than the first. Review all uses of square brackets in the statement to find the error. Possibly the size of a column has been altered and makes a substring fail that used to work.
Oninit® Troubleshooting Guidance
Reasons / Common Causes
-307 covers the same general problem as -306 — malformed subscript bounds in a column[m,n]
expression, where the first value is negative or exceeds the column length, or the second value
is less than the first — but at the point the subscript expression itself is being defined/parsed,
rather than a runtime bounds check against actual row data. In practice this typically means the
subscript literals themselves are structurally wrong, not just wrong relative to a particular
row's data.
- A negative or non-sensical subscript literal written directly into the query — a mistake in the SQL text itself, not something dependent on row data.
- A subscript expression with the wrong number of values or malformed syntax within the brackets.
- A schema/column-size change making a previously valid subscript definition invalid for the
column's current length — same root-cause family as
-306. - Copy-pasted or templated subscript expressions carried over from a different column with a different length, without adjusting the bounds.
Solutions / Resolution
- Review all square-bracket subscript usage in the statement, per the official guidance, for negative, out-of-range, or backwards values.
- Confirm the column's current declared length if the query used to work — a size change is a common trigger.
- Avoid copy-pasting subscript expressions between columns of different lengths without adjusting the bounds to match.
Examples
A structurally invalid subscript definition
SELECT description[-1,10] FROM parts;
-- -307: a negative start subscript
Fix — use valid, positive bounds within the column's length:
SELECT description[1,10] FROM parts;
Copy-pasted subscript bounds from a differently-sized column
-- part_code is VARCHAR(10); description is VARCHAR(100).
-- Bounds copied from a description query onto part_code:
SELECT part_code[1,80] FROM parts;
-- -307: 80 exceeds part_code's declared length of 10
Fix — use bounds appropriate to the actual column:
SELECT part_code[1,10] FROM parts;
Diagnostic Checks
- Review every subscript expression's literal values for negative numbers, backwards ranges, or bounds exceeding the target column's declared length.
- Check for a recent column-size change if a previously valid subscript definition started failing.
Related Errors / Related Topics
- -306 — "Subscript out of range." The closest sibling, covering the same kind of malformed bound but evaluated against actual row/column data at runtime rather than at definition time.
- -305 — "Subscripted column column-name is not of type CHAR, VARCHAR, TEXT nor BYTES." The type-level restriction subscript notation is also subject to.
The fix is the same discipline as -306: check both subscript bounds are non-negative, in
correct order, and consistent with the actual column's current length.