3166
MariaDBERRORNotableWindow FunctionsHIGH confidence

Derived window cannot inherit a frame from a base window with ORDER BY

Production Risk

Low — syntax error.

What this means

A derived window that adds its own frame specification cannot inherit from a base window that has an ORDER BY clause, because the frame would be ambiguous.

Why it happens
  1. 1Inheriting from a named window with ORDER BY while the derived window also specifies a frame clause (ROWS/RANGE BETWEEN).
How to reproduce
trigger — this will error
trigger — this will error
SELECT SUM(val) OVER (w ROWS BETWEEN 1 PRECEDING AND CURRENT ROW) FROM t1 WINDOW w AS (ORDER BY id);

expected output

ERROR 3166 (HY000): Derived window cannot inherit a frame from a named window with ORDER BY.

Fix

Define frame and ORDER BY together in an inline window

Define frame and ORDER BY together in an inline window
SELECT SUM(val) OVER (ORDER BY id ROWS BETWEEN 1 PRECEDING AND CURRENT ROW) FROM t1;

Why this works

Inline definition avoids inheritance ambiguity.

What not to do

Sources
Official documentation ↗

MySQL 8.0 — 3166 ER_WINDOW_NO_INHERIT_FRAME

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All MariaDB errors