Re: Aggregate functions on ordered data? - Mailing list pgsql-general

From Tom Lane
Subject Re: Aggregate functions on ordered data?
Date
Msg-id 14531.1056321953@sss.pgh.pa.us
Whole thread Raw
In response to Aggregate functions on ordered data?  (Andreas Lehrbaum <andreas.lehrbaum@kabelweb.at>)
List pgsql-general
Andreas Lehrbaum <andreas.lehrbaum@kabelweb.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

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: Schemas and access
Next
From: Ron Johnson
Date:
Subject: Re: A creepy story about dates. How to prevent it?