X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 9A8F730F858 for ; Mon, 9 Jun 2003 18:47:20 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 58687-07 for ; Mon, 9 Jun 2003 18:47:10 +0000 (GMT) Received: from www.postgresql.com (www.postgresql.com [64.117.225.209]) by svr1.postgresql.org (Postfix) with ESMTP id 4120330F86A for ; Mon, 9 Jun 2003 03:04:14 +0000 (GMT) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by www.postgresql.com (Postfix) with ESMTP id 0EE50CF817D for ; Mon, 9 Jun 2003 01:15:01 +0000 (GMT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h5915tU6003650; Sun, 8 Jun 2003 21:05:55 -0400 (EDT) To: Eivind Kvedalen Cc: Michael A Nachbaur , pgsql-sql@postgresql.org Subject: Re: "Join" on delimeter aggregate query In-reply-to: References: <200306061003.29430.mike@nachbaur.com> Comments: In-reply-to Eivind Kvedalen message dated "Sat, 07 Jun 2003 23:06:36 +0200" Date: Sun, 08 Jun 2003 21:05:55 -0400 Message-ID: <3649.1055120755@sss.pgh.pa.us> From: Tom Lane X-Archive-Number: 200306/64 X-Sequence-Number: 13822 Eivind Kvedalen 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