v.24.6Improvement

Second Argument of Round Functions Now Non-Const

The second argument (scale) of functions round(), roundBankers(), floor(), ceil() and trunc() can now be non-const. #64798 (Mikhail Gorshkov).
The second argument (scale) of the functions round(), roundBankers(), floor(), ceil(), and trunc() can now be non-constant, allowing dynamic scaling during execution.

Why it matters

Previously, the scale argument for these rounding and truncation functions had to be a constant value, limiting flexibility in queries where the scale needed to vary dynamically. This enhancement enables users to apply different scale values per row or parameterize scale at runtime, making numeric rounding and truncation more versatile and adaptable to varied data processing needs.

How to use it

Simply pass a non-constant expression as the second argument (scale) to the functions round(), roundBankers(), floor(), ceil(), or trunc(). For example:
SELECT round(value, dynamic_scale) FROM table

where dynamic_scale can be a column or an expression evaluated at runtime.