Re: Aggregate functions on ordered data?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Andreas Lehrbaum <andreas(dot)lehrbaum(at)kabelweb(dot)at>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Aggregate functions on ordered data?
Date: 2003-06-22 22:45:53
Message-ID: 14531.1056321953@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Andreas Lehrbaum <andreas(dot)lehrbaum(at)kabelweb(dot)at> writes:
> Is it possible in _any_ way to control the order of the rows passed to an
> aggregate function?

For simple aggregation you can do

SELECT myagg(col) FROM (SELECT col FROM ... ORDER BY foo) ss;

If you wanted to group, you could try

SELECT gcol, myagg(col) FROM
(SELECT gcol, col FROM ... ORDER BY gcol, foo) ss
GROUP BY gcol;

but this does *not* work reliably in current releases (it will work in
7.4 though). See the archives.

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Ron Johnson 2003-06-22 23:39:40 Re: A creepy story about dates. How to prevent it?
Previous Message btober 2003-06-22 22:43:21 Re: Schemas and access