3180
MySQLERRORNotableWindow FunctionsHIGH confidence

RANGE frame impossible for row type

Production Risk

Low — caught at parse/validation time.

Why it happens
  1. 1Using RANGE frame with a data type that does not support ordered range calculations.
  2. 2Row type is incompatible with RANGE semantics.
How to reproduce
trigger — this will error
trigger — this will error
SELECT SUM(val) OVER (ORDER BY col RANGE BETWEEN 1 PRECEDING AND CURRENT ROW) FROM t1;

expected output

ERROR 3180 (HY000): RANGE frame with PRECEDING/FOLLOWING cannot use this row type.

Fix 1

Switch to ROWS frame

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

Why this works

ROWS frame works with all data types.

Fix 2

Cast the ORDER BY column to a numeric type

Cast the ORDER BY column to a numeric type
SELECT SUM(val) OVER (ORDER BY CAST(col AS DECIMAL(10,2)) RANGE BETWEEN 1 PRECEDING AND CURRENT ROW) FROM t1;

Why this works

RANGE requires numeric or datetime ORDER BY.

What not to do

Sources
Official documentation ↗

MySQL 8.0 — 3180 ER_WINDOW_RANGE_FRAME_IMPOSSIBLE_ROWTYPE

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

← All MySQL errors