3176
MySQLERRORNotableWindow FunctionsHIGH confidence

UNBOUNDED FOLLOWING can only be the frame end, not start

Production Risk

Low — syntax error.

What this means

UNBOUNDED FOLLOWING is only valid as the frame end specification (the second bound in BETWEEN). Using it as the start bound is semantically invalid.

Why it happens
  1. 1Writing ROWS/RANGE BETWEEN UNBOUNDED FOLLOWING AND ... instead of ... AND UNBOUNDED FOLLOWING.
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 3176 (HY000): UNBOUNDED FOLLOWING is not allowed as a frame start.

Fix

Correct the frame bounds order

Correct the frame bounds order
SELECT SUM(val) OVER (ORDER BY id ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING) FROM t1;

Why this works

UNBOUNDED FOLLOWING as the end bound is valid and includes all rows after the current row.

What not to do

Sources
Official documentation ↗

MySQL 8.0 — 3176 ER_WINDOW_UNBOUNDED_FOLLOWING_ONLY_IN_UNBOUNDED

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

← All MySQL errors