3165
MariaDBERRORNotableWindow FunctionsHIGH confidence
Derived window cannot define PARTITION BY if base window does
Production Risk
Low — syntax error.
What this means
When a window definition inherits from a named base window (by referencing it in the window spec), the derived window cannot add its own PARTITION BY clause if the base window already specifies PARTITION BY.
Why it happens
- 1A window definition that inherits from a named window also specifies PARTITION BY.
How to reproduce
trigger — this will error
trigger — this will error
SELECT SUM(val) OVER (w PARTITION BY cat) FROM t1 WINDOW w AS (PARTITION BY grp ORDER BY id);
expected output
ERROR 3165 (HY000): Derived window cannot define partitioning if parent window already does.
Fix 1
Remove PARTITION BY from the derived window
Remove PARTITION BY from the derived window
SELECT SUM(val) OVER w FROM t1 WINDOW w AS (PARTITION BY grp ORDER BY id);
Why this works
Inherit the full window definition from the named window.
Fix 2
Define all partitioning in the derived window spec
Define all partitioning in the derived window spec
SELECT SUM(val) OVER (PARTITION BY cat ORDER BY id) FROM t1;
Why this works
Define the complete window inline without inheritance.
What not to do
✕
Sources
Official documentation ↗
MySQL 8.0 — 3165 ER_WINDOW_NO_CHILD_PARTITIONING
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev