Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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 )

share|improve this question
    
As far as I know, aggregates may not return a rowset. You'd need to use arrays. –  Craig Ringer Feb 4 '14 at 1:18

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.