3268
MariaDBERRORNotableWindow FunctionsHIGH confidence
RANGE frame with interval offset requires datetime ORDER BY
Production Risk
Low — query is rejected; correct the ORDER BY column type.
How to reproduce
trigger — this will error
trigger — this will error
SELECT SUM(amount) OVER (ORDER BY sale_id RANGE BETWEEN INTERVAL 7 DAY PRECEDING AND CURRENT ROW) FROM sales;
expected output
ERROR 3268 (HY000): Window 'w': RANGE with INTERVAL PRECEDING/FOLLOWING requires datetime ORDER BY.
Fix
Use datetime ORDER BY
Use datetime ORDER BY
SELECT SUM(amount) OVER (ORDER BY sale_date RANGE BETWEEN INTERVAL 7 DAY PRECEDING AND CURRENT ROW) FROM sales;
Why this works
INTERVAL offsets work with DATE/DATETIME ORDER BY columns.
What not to do
✕
Sources
Official documentation ↗
MySQL 8.0 — 3268 ER_WINDOW_RANGE_FRAME_DATETIME_TYPE2
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev