3177
MySQLERRORNotableWindow FunctionsHIGH confidence

EXCLUDE CURRENT ROW requires BETWEEN frame

Production Risk

Low — syntax error.

What this means

A window frame EXCLUDE clause (such as EXCLUDE CURRENT ROW or EXCLUDE GROUP) was specified but the frame definition does not use a BETWEEN clause, which is required for frame exclusions.

Why it happens
  1. 1Specifying EXCLUDE without a BETWEEN frame definition.
How to reproduce
trigger — this will error
trigger — this will error
SELECT SUM(val) OVER (ORDER BY id ROWS UNBOUNDED PRECEDING EXCLUDE CURRENT ROW) FROM t1;

expected output

ERROR 3177 (HY000): Frame exclusion requires a BETWEEN frame.

Fix

Use BETWEEN with EXCLUDE

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

Why this works

BETWEEN frame with EXCLUDE correctly defines the frame extent and the excluded rows.

What not to do

Sources
Official documentation ↗

MySQL 8.0 — 3177 ER_WINDOW_FRAME_EXCLUSIVE_REQUIRES_CURRENT_ROW

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

← All MySQL errors