Contents

histogram()

We write a function which runs width_bucket on each value to be aggregated and uses that to increment the corresponding bucket. The state is stored as an array of integers. The array has an element with index zero holding the count of values < MIN and an element with index (nbuckets+1) holding the count of values >= MAX.

This aggregate should work for PostgreSQL > 9.0, but it was only tested with PostgreSQL 9.6.