3189
MySQLERRORNotableWindow FunctionsHIGH confidence
Window functions not supported in this context
Production Risk
Medium — requires query restructuring.
Why it happens
- 1Using window functions in WHERE, HAVING, or GROUP BY clauses.
- 2Window functions are only valid in SELECT list and ORDER BY.
How to reproduce
trigger — this will error
trigger — this will error
SELECT * FROM t1 WHERE ROW_NUMBER() OVER (ORDER BY id) > 5;
expected output
ERROR 3189 (HY000): Window functions are not allowed in the WHERE clause.
Fix
Wrap in a subquery
Wrap in a subquery
SELECT * FROM (SELECT *, ROW_NUMBER() OVER (ORDER BY id) AS rn FROM t1) sub WHERE rn > 5;
Why this works
Window functions are evaluated after WHERE; use a derived table to filter on their result.
What not to do
✕
Sources
Official documentation ↗
MySQL 8.0 — 3189 ER_WINDOW_FUNCTIONS_UNSUPPORTED
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev