Is it possible for a Postgres aggregate function to return multiple rows?
For example, in the same way that regexp_matches
will return multiple rows when the g
flag is passed, is I'd like to create an aggregate function which returns a histogram over the aggregated value, one row per bucket. For example, something like:
> SELECT histogram(price, 0, 100, 10) FROM sales
bucket_start | bucket_end | count
0 | 10 | 5
10 | 20 | 7
20 | 30 | 9
Is this possible? And, if so, what would be the syntax? (right now I'm using the aggregate histogram function from https://wiki.postgresql.org/wiki/Aggregate_Histogram )