X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 884B9D1E0D0 for ; Wed, 18 Feb 2004 09:29:46 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 37149-03 for ; Wed, 18 Feb 2004 05:29:46 -0400 (AST) Received: from anchor-post-30.mail.demon.net (anchor-post-30.mail.demon.net [194.217.242.88]) by svr1.postgresql.org (Postfix) with ESMTP id 7901AD1E0C5 for ; Wed, 18 Feb 2004 05:29:44 -0400 (AST) Received: from mwynhau.demon.co.uk ([193.237.186.96] helo=mainbox.archonet.com) by anchor-post-30.mail.demon.net with esmtp (Exim 3.35 #1) id 1AtO1Z-000MK3-0U; Wed, 18 Feb 2004 09:29:45 +0000 Received: by mainbox.archonet.com (Postfix, from userid 529) id A947A16B01; Wed, 18 Feb 2004 09:29:44 +0000 (GMT) Received: from client17.archonet.com (client17.archonet.com [192.168.1.17]) by mainbox.archonet.com (Postfix) with ESMTP id 73D2315901; Wed, 18 Feb 2004 09:29:42 +0000 (GMT) From: Richard Huxton To: Tom Lane Subject: Re: Return relation table data in a single value CSV Date: Wed, 18 Feb 2004 09:29:42 +0000 User-Agent: KMail/1.5 Cc: terry@ashtonwoodshomes.com, "Postgresql Sql Group (E-mail)" References: <007701c3f591$5acc3020$2766f30a@development.greatgulfhomes.com> <200402172104.38307.dev@archonet.com> <18788.1077060834@sss.pgh.pa.us> In-Reply-To: <18788.1077060834@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200402180929.42103.dev@archonet.com> X-Bogosity: No, tests=bogofilter, spamicity=0.000000, version=0.15.3 X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200402/247 X-Sequence-Number: 16937 On Tuesday 17 February 2004 23:33, Tom Lane wrote: > Richard Huxton writes: > > 2. Write a custom aggregate function (like sum()) to do the > > concatenation. This is easy to do, but the order your ABC get processed > > in is undefined. > > Actually, as of 7.4 it is possible to control the order of inputs to a > custom aggregate. You do something like this: > > SELECT foo, myagg(bar) FROM > (SELECT foo, bar FROM table ORDER BY foo, baz) AS ss > GROUP BY foo > > The inner sub-select must order by the columns that the outer will group > on; it can then order by additional columns that determine the sort > order within each group. Here, myagg() will see its input ordered by > increasing values of baz. Hmm - good to know, but I'm always wary of doing this sort of thing. It's exactly the sort of trick I look at 18 months later, fail to read my own comments and "tidy" it. -- Richard Huxton Archonet Ltd