2

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 )

1
  • As far as I know, aggregates may not return a rowset. You'd need to use arrays. Commented Feb 4, 2014 at 1:18

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.