From: Tom Lane <tgl@sss.pgh.pa.us>
To: Eivind Kvedalen <eivindkv@ifi.uio.no>
Cc: Michael A Nachbaur <mike@nachbaur.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: "Join" on delimeter aggregate query
Date: Sun, 08 Jun 2003 21:05:55 -0400
Message-ID: <3649.1055120755@sss.pgh.pa.us> (raw)
In-Reply-To: <Pine.SOL.4.51.0306072257180.25070@tva.ifi.uio.no>
References: <200306061003.29430.mike@nachbaur.com>
<Pine.SOL.4.51.0306072257180.25070@tva.ifi.uio.no>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: tgl@sss.pgh.pa.us, eivindkv@ifi.uio.no, mike@nachbaur.com
Subject: Re: "Join" on delimeter aggregate query
In-Reply-To: <3649.1055120755@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox