3163
MariaDBERRORNotableWindow FunctionsHIGH confidence
RANGE frame bound must be a constant
Production Risk
Low — syntax error caught at parse time.
What this means
A window frame specified with RANGE mode requires that the frame bound value be a literal constant. Using a column reference or variable expression as a RANGE bound is not permitted.
Why it happens
- 1Using a column or computed expression as the bound in RANGE BETWEEN ... PRECEDING AND ... FOLLOWING.
How to reproduce
trigger — this will error
trigger — this will error
SELECT SUM(val) OVER (ORDER BY dt RANGE BETWEEN interval_col PRECEDING AND CURRENT ROW) FROM t1;
expected output
ERROR 3163 (HY000): Window frame bound must be a constant for RANGE frames.
Fix 1
Use a literal constant for RANGE bounds
Use a literal constant for RANGE bounds
SELECT SUM(val) OVER (ORDER BY dt RANGE BETWEEN INTERVAL 7 DAY PRECEDING AND CURRENT ROW) FROM t1;
Why this works
Literal interval bounds are valid RANGE frame specifications.
Fix 2
Switch to ROWS mode if dynamic bounds are needed
Switch to ROWS mode if dynamic bounds are needed
SELECT SUM(val) OVER (ORDER BY dt ROWS BETWEEN 6 PRECEDING AND CURRENT ROW) FROM t1;
Why this works
ROWS mode counts physical rows and accepts literal integer bounds.
What not to do
✕
Sources
Official documentation ↗
MySQL 8.0 — 3163 ER_WINDOW_RANGE_BOUND_NOT_CONSTANT
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev