Informix Error -686
-686 Function <function-name> has returned more than one row. </function-name>
A function returned more than one row of values (for example, it executed RETURN...WITH RESUME) when the caller expected only one row of values.
Example of error:
CREATE FUNCTION testroutine (limit INT) RETURNING INT; DEFINE i INT; FOR i IN (1 TO limit) RETURN i WITH RESUME; END FOR END FUNCTION;
CREATE FUNCTION gettest() RETURNING INT; DEFINE var INT; LET var = testroutine (10); -- error RETURN var; END FUNCTION;
Oninit® Troubleshooting Guidance
Reasons / Common Causes
-686 fires when a routine using RETURN ... WITH RESUME (which can produce multiple rows of
output, iterator-style) is called from a context expecting only a single row of values — per the
official guidance's example, a routine producing multiple rows called by another routine that
expects a single return.
- A routine written with
RETURN ... WITH RESUME(making it a row-producing iterator routine) called somewhere that only handles one row of results, per the official guidance's example. - A routine intended as a single-row function, but mistakenly using
WITH RESUMEinstead of a plainRETURN, causing it to behave as a multi-row iterator unintentionally. - A routine genuinely meant to produce multiple rows, called via a mechanism (like
LETor a scalar expression) that only accepts one row, instead of viaFOREACHor a table context that can consume multiple rows.
Solutions / Resolution
- If a single value was intended, use a plain
RETURNinstead ofRETURN ... WITH RESUMEin the routine's own definition — this is likely the actual bug if only one row was ever meant to come back. - If multiple rows are genuinely intended, call the routine from a context that can consume
them, such as
FOREACH:
rather than a single-valueFOREACH EXECUTE FUNCTION testroutine() INTO v_val ... END FOREACH;LET/expression context. - Review why the routine has
WITH RESUMEat all if it was copy-pasted from an iterator-style routine template without needing that behavior.
Examples
The disallowed mismatch
CREATE FUNCTION testroutine()
RETURNING INT;
FOR i = 1 TO 3
RETURN i WITH RESUME;
END FOR;
END FUNCTION;
CREATE FUNCTION gettest()
RETURNING INT;
DEFINE v_val INT;
LET v_val = testroutine();
-- -686: testroutine returns multiple rows, this context expects one
RETURN v_val;
END FUNCTION;
Corrected — consume multiple rows via FOREACH
CREATE FUNCTION gettest()
RETURNING INT;
DEFINE v_val, v_last INT;
FOREACH EXECUTE FUNCTION testroutine() INTO v_val
LET v_last = v_val;
END FOREACH;
RETURN v_last;
END FUNCTION;
Diagnostic Checks
- Check whether the called routine uses
RETURN ... WITH RESUME, and whether the caller is set up to consume multiple rows (FOREACH) or only a single value (LET/expression).
Related Errors / Related Topics
- -684 — "Function function-name returns too many values." A related return-mismatch error, about too many values in one row rather than too many rows.
- -685 — "Function function-name returns too few values." A related return-mismatch error, about too few values in one row.
RETURN ... WITH RESUME makes a routine multi-row — call it via FOREACH (or a similar
multi-row-capable context) rather than a single-value assignment.