3184
MariaDBERRORNotableWindow FunctionsHIGH confidence

RANGE frame offset must be interval for datetime ORDER BY

Production Risk

Low — caught at validation time.

Why it happens
  1. 1Using a plain numeric offset with a datetime ORDER BY column in a RANGE frame.
  2. 2Datetime ORDER BY requires an INTERVAL offset for RANGE frames.
How to reproduce
trigger — this will error
trigger — this will error
SELECT SUM(val) OVER (ORDER BY dt_col RANGE BETWEEN 5 PRECEDING AND CURRENT ROW) FROM t1;

expected output

ERROR 3184 (HY000): Window RANGE frame with PRECEDING/FOLLOWING requires INTERVAL for datetime ORDER BY.

Fix 1

Use INTERVAL offset

Use INTERVAL offset
SELECT SUM(val) OVER (ORDER BY dt_col RANGE BETWEEN INTERVAL 5 DAY PRECEDING AND CURRENT ROW) FROM t1;

Why this works

INTERVAL expressions match datetime arithmetic semantics.

Fix 2

Switch to ROWS frame

Switch to ROWS frame
SELECT SUM(val) OVER (ORDER BY dt_col ROWS BETWEEN 5 PRECEDING AND CURRENT ROW) FROM t1;

Why this works

ROWS frame uses row counts, avoiding type mismatch.

What not to do

Sources
Official documentation ↗

MySQL 8.0 — 3184 ER_WINDOW_RANGE_FRAME_DATETIME_TYPE

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

← All MariaDB errors