3183
MySQLERRORNotableWindow FunctionsHIGH confidence

RANGE frame offset must be numeric

Production Risk

Low — caught at validation time.

Why it happens
  1. 1RANGE frame PRECEDING/FOLLOWING offset is not a numeric value when ORDER BY is numeric.
  2. 2Mismatched types between the offset value and the ORDER BY column.
How to reproduce
trigger — this will error
trigger — this will error
SELECT SUM(val) OVER (ORDER BY num_col RANGE BETWEEN 'abc' PRECEDING AND CURRENT ROW) FROM t1;

expected output

ERROR 3183 (HY000): Window RANGE frame with PRECEDING/FOLLOWING requires numeric type for ORDER BY expression.

Fix

Use a numeric literal as offset

Use a numeric literal as offset
SELECT SUM(val) OVER (ORDER BY num_col RANGE BETWEEN 5 PRECEDING AND CURRENT ROW) FROM t1;

Why this works

The offset must be a non-negative numeric constant matching the ORDER BY column type.

What not to do

Sources
Official documentation ↗

MySQL 8.0 — 3183 ER_WINDOW_RANGE_FRAME_NUMERIC_TYPE

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

← All MySQL errors