v.23.3New Feature

Introduce widthBucket function with WIDTH_BUCKET alias

Introduce a function widthBucket (with a WIDTH_BUCKET alias for compatibility). #42974. #46790 (avoiderboi).
Introduces the widthBucket function (aliased as WIDTH_BUCKET) for bucketizing numeric data into specified ranges.

Why it matters

The widthBucket function provides users with a way to assign values into equi-width buckets or histogram bins. This is useful for data analysis tasks such as distribution segmentation, histogram creation, and range-based categorization, enhancing analytical capabilities within ClickHouse.

How to use it

Use the widthBucket function by calling it in your SQL queries to divide a numeric value into buckets. The function syntax is similar to:

SELECT widthBucket(value, min_value, max_value, bucket_count) FROM table


where value is the input number, min_value and max_value define the range for bucketing, and bucket_count specifies the number of buckets. The WIDTH_BUCKET alias can be used interchangeably.