3182
MySQLERRORNotableWindow FunctionsHIGH confidence

Illegal window frame start specification

Production Risk

Low — parse-time error.

Why it happens
  1. 1Using an illegal frame start specification such as UNBOUNDED FOLLOWING as the start.
  2. 2Frame start cannot logically be after the frame end.
How to reproduce
trigger — this will error
trigger — this will error
SELECT SUM(val) OVER (ORDER BY id ROWS BETWEEN UNBOUNDED FOLLOWING AND CURRENT ROW) FROM t1;

expected output

ERROR 3182 (HY000): Window frame start illegal.

Fix 1

Use UNBOUNDED PRECEDING as frame start

Use UNBOUNDED PRECEDING as frame start
SELECT SUM(val) OVER (ORDER BY id ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) FROM t1;

Why this works

UNBOUNDED PRECEDING is the correct unbounded start.

Fix 2

Use CURRENT ROW as frame start

Use CURRENT ROW as frame start
SELECT SUM(val) OVER (ORDER BY id ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING) FROM t1;

Why this works

CURRENT ROW is always a valid frame start.

What not to do

Sources
Official documentation ↗

MySQL 8.0 — 3182 ER_WINDOW_FRAME_START_ILLEGAL

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

← All MySQL errors