Re: "Join" on delimeter aggregate query - Mailing list pgsql-sql

From Tom Lane
Subject Re: "Join" on delimeter aggregate query
Date
Msg-id 3649.1055120755@sss.pgh.pa.us
Whole thread Raw
In response to Re: "Join" on delimeter aggregate query  (Eivind Kvedalen <eivindkv@ifi.uio.no>)
Responses Re: "Join" on delimeter aggregate query
List pgsql-sql
Eivind Kvedalen <eivindkv@ifi.uio.no> writes:
> SELECT a, concat(b) FROM (SELECT a,b FROM test ORDER BY a,b) T GROUP BY a;

> The ORDER BY is included to sort the rows before they are aggregated. I'm
> not sure that this guarantees that they actually will be sorted, but maybe
> some of the postgresql hackers can confirm/deny this?

This technique will work reliably as of 7.4, but it's not reliable
in existing releases.  The GROUP BY will do its own sort on A, and
unless qsort() is stable on your machine (which it's not, in most
implementations) the secondary ordering by B will be destroyed.

The fix in 7.4 simply makes the planner smart enough to notice that
the sub-select's output is already adequately sorted for grouping
by A.
        regards, tom lane


pgsql-sql by date:

Previous
From: Rod Taylor
Date:
Subject: Re: Column limits in table/ views
Next
From: "Gaetano Mendola"
Date:
Subject: Re: Column limits in table/ views