v.1.1.54292New Feature
Added trunc function and improved rounding performance and logic
Added thetruncfunction. Improved performance of the rounding functions (round,floor,ceil,roundToExp2) and corrected the logic of how they work. Changed the logic of theroundToExp2function for fractions and negative numbers.
Why it matters
The addition of the trunc function and improvements to rounding functions address the need for more efficient and logically correct numeric rounding operations in ClickHouse. This enables users to perform truncation and rounding with better performance and more consistent results, particularly in edge cases like fractional values and negatives, thereby improving data processing accuracy and speed.How to use it
Use the trunc function to truncate decimal numbers to their integer part or specified precision. The rounding functionsround, floor, ceil, and roundToExp2 can be used as before but now perform faster and with corrected logic. For example:SELECT trunc(12.345) -- returns 12
SELECT round(-3.7) -- applies corrected rounding logic
SELECT roundToExp2(10.75, -1) -- rounding adjusted for fractions/negative inputs