Informix Error -306
-306 Subscript out of range.
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
-306 fires on malformed subscript bounds in a substring reference like column[m,n]: the start
value is less than zero or greater than the column's length, or the end value is less than the
start value.
- A start subscript less than one or greater than the column's declared length — an off-by-one mistake, or a hardcoded bound that no longer matches the column's actual size.
- An end subscript less than the start subscript — the range is backwards (e.g.
[5,2]instead of[2,5]). - A column's declared length changed (
ALTER TABLE MODIFYshrinking aVARCHAR/CHARcolumn) since the subscript expression was written, breaking a previously-working query. - Hardcoded subscript bounds based on an assumed fixed format that doesn't hold for every row — a variable-length value shorter than the assumed subscript range.
Solutions / Resolution
- Verify both subscript bounds are within the column's actual current length, per the official guidance, and that the start is less than or equal to the end.
- If a column's length was recently changed, review any subscript expressions against it for now-invalid ranges.
- For variable-length data, avoid hardcoded subscript ranges that assume a fixed format —
use
LENGTH()to compute bounds dynamically, or validate the value's length before subscripting it.
Examples
Backwards subscript range
SELECT name[5,2] FROM customers;
-- -306: end (2) is less than start (5)
Fix — correct the order:
SELECT name[2,5] FROM customers;
A column shrunk since the query was written
-- Column was VARCHAR(50); query assumed a fixed layout:
SELECT code[40,45] FROM parts;
-- After: ALTER TABLE parts MODIFY (code VARCHAR(30));
-- The same query now fails:
SELECT code[40,45] FROM parts;
-- -306: 40 exceeds the column's new length of 30
Fix — update the subscript bounds to match the current column length, or compute them dynamically:
SELECT code[1, LENGTH(code)] FROM parts;
Diagnostic Checks
- Check the column's current declared length and compare against the subscript bounds used.
- Confirm the start subscript is less than or equal to the end subscript.
- Review recent
ALTER TABLE MODIFYhistory on the column if a previously-working query started failing.
Related Errors / Related Topics
- -305 — "Subscripted column column-name is not of type CHAR, VARCHAR, TEXT nor BYTES." The closest sibling — a related restriction on subscript notation, about column type rather than bounds.
- -219 — "Wildcard matching may not be used with non-character types." Another character-family-specific operator restriction.
Check the column's current length before trusting hardcoded subscript bounds — a schema change can silently invalidate a previously-working substring expression.