Re: Order By for aggregate functions (Simulating Group_concat)

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Michael Fuhr <mike(at)fuhr(dot)org>
Cc: Charlotte Pollock <c(dot)pollock(at)bangor(dot)ac(dot)uk>, pgsql-general(at)postgresql(dot)org
Subject: Re: Order By for aggregate functions (Simulating Group_concat)
Date: 2005-09-01 18:07:16
Message-ID: 4849.1125598036@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Michael Fuhr <mike(at)fuhr(dot)org> writes:
> On Thu, Sep 01, 2005 at 05:14:41PM +0200, Martijn van Oosterhout wrote:
>> SELECT aggregate(field) FROM (SELECT field FROM xxx ORDER BY wherever) x;

> I've occasionally relied on this but I've never been completely
> comfortable with it. Is there any guarantee that the subquery's
> ordering will be maintained as rows are fed to the aggregate, or
> is that just an accident of the current implementation?

Well, it's not required by the SQL spec (in fact I believe ORDER BY
inside a subselect isn't even legal per the SQL spec) ... but we do
promise it in the current implementation and I doubt we'd break the
promise in future, because it is a mighty handy behavior for
user-defined aggregates.

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Federico Balbi 2005-09-01 18:34:41 query
Previous Message Casey T. Deccio 2005-09-01 18:06:00 Re: Transaction error