Informix Error -25856: Invalid usage of window aggregate in this context.
Cause and resolution
Invalid usage of window aggregate in this context.
You can use OLAP window aggregate functions in the Projection clause and in the ORDER BY clause of queries. They cannot be present in the WHERE clause or in the HAVING clause (except within a subquery).
Oninit® Troubleshooting Guidance
Reasons / Common Causes
-25856 fires when an OLAP window aggregate function is used outside the projection or
ORDER BY clause — per the official guidance, window aggregates can only appear in the
projection clause and ORDER BY, and are disallowed in WHERE/HAVING (except within a
subquery).
- A window aggregate used in
WHEREorHAVING, per the official guidance — outside of a subquery context.
Solutions / Resolution
- Move the window aggregate to the projection clause or
ORDER BY, per the official guidance, or wrap it inside a subquery ifWHERE/HAVING-style filtering on its result is needed.
Examples
A window aggregate in WHERE
SELECT * FROM orders WHERE SUM(total) OVER (PARTITION BY customer_id) > 1000;
-- -25856: window aggregate isn't allowed directly in WHERE
Corrected — via a subquery
SELECT * FROM (
SELECT o.*, SUM(total) OVER (PARTITION BY customer_id) AS cust_total FROM orders o
) WHERE cust_total > 1000;
Diagnostic Checks
- Check whether the window aggregate appears in
WHERE/HAVINGoutside a subquery, and move it to the projection clause,ORDER BY, or a subquery.
Related Errors / Related Topics
- -25855 — "The option specified is not supported in window aggregates." A related window aggregate restriction, on what the aggregate itself can contain rather than where it can appear.
A window aggregate appeared directly in WHERE/HAVING — move it to the projection
clause, ORDER BY, or a subquery.