Informix Error -4341
-4341 Aggregate functions are only allowed in reports and SELECT statements.
Aggregate functions such as SUM, AVG, and MAX can only appear in SQL statements and within certain statements you use in the context of a report body. They are not supported in ordinary expressions in program statements. You might be able to write an application-specific function to form this aggregate function on your data; however, you must name it something else because names such as SUM, AVG, and MAX are reserved words.
Oninit® Troubleshooting Guidance
Reasons / Common Causes
-4341 fires when an aggregate function such as SUM, AVG, or MAX is used in an ordinary
program expression — per the official guidance, these are only supported in SQL statements
and within certain report-body statements.
- An aggregate function used in an ordinary program expression, per the official guidance — the direct, only cause.
Solutions / Resolution
- Use the aggregate within a SQL statement or a report body instead, per the official guidance.
- If application-specific aggregation logic is needed, write your own function with a
different name, per the official guidance —
SUM,AVG,MAX, and similar names are reserved words and can't be reused.
Examples
An aggregate used in a plain expression
LET total = SUM(qty)
-- -4341: SUM cannot be used outside SQL statements/report bodies
Corrected
SELECT SUM(qty) INTO total FROM order_items WHERE order_id = 1001;
Diagnostic Checks
- Check every use of an aggregate function, and confirm it's inside a SQL statement or report body, not a plain program expression.
Related Errors / Related Topics
No closely related error codes are cross-referenced for -4341 in this set yet.
An aggregate function is used in an ordinary expression — move it into a SQL statement or report body, or write a custom function under a different name.