Re: Grouping, Aggregate, Min, Max

From: Kevin Grittner <kgrittn(at)ymail(dot)com>
To: Misa Simic <misa(dot)simic(at)gmail(dot)com>, pgsql <pgsql-general(at)postgresql(dot)org>
Subject: Re: Grouping, Aggregate, Min, Max
Date: 2013-12-13 20:13:40
Message-ID: 1386965620.18832.YahooMailNeo@web162902.mail.bf1.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Misa Simic <misa(dot)simic(at)gmail(dot)com> wrote:

> So I wonder - is there some kind of aggregate window function
> what does desired results?

Not built in, but PostgreSQL makes it pretty easy to do so.  With a
little effort to define your own aggregate function, your query can
look like this:

SELECT
    thing_id,
    category,
    int4range_list(period_id)
  FROM thing
  GROUP BY thing_id, category
  ORDER BY 1, 2;

I've attached a couple files -- one which creates the desired
aggregate function, and the other loads a table with two of your
sample data sets and runs the above.  This is just intended as a
quick example of the capabilities available to you.

--
Kevin Grittner
EDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

Attachment Content-Type Size
int4range_list.sql text/x-sql 2.4 KB
thing.sql text/x-sql 718 bytes

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Roy Anderson 2013-12-13 21:57:00 Data Guard for Postgres?
Previous Message salah jubeh 2013-12-13 19:10:48 Re: design for multiple time series