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 8550AD1D501 for ; Tue, 17 Feb 2004 21:04:48 +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 41280-08 for ; Tue, 17 Feb 2004 17:04:43 -0400 (AST) Received: from anchor-post-34.mail.demon.net (anchor-post-34.mail.demon.net [194.217.242.92]) by svr1.postgresql.org (Postfix) with ESMTP id 5DE29D1D4E7 for ; Tue, 17 Feb 2004 17:04:41 -0400 (AST) Received: from mwynhau.demon.co.uk ([193.237.186.96] helo=mainbox.archonet.com) by anchor-post-34.mail.demon.net with esmtp (Exim 3.35 #1) id 1AtCOX-000IUB-0Y; Tue, 17 Feb 2004 21:04:41 +0000 Received: by mainbox.archonet.com (Postfix, from userid 529) id 15EE4163B8; Tue, 17 Feb 2004 21:04:41 +0000 (GMT) Received: from client17.archonet.com (client17.archonet.com [192.168.1.17]) by mainbox.archonet.com (Postfix) with ESMTP id 1B9BE15A87; Tue, 17 Feb 2004 21:04:39 +0000 (GMT) From: Richard Huxton To: , "Postgresql Sql Group (E-mail)" Subject: Re: Return relation table data in a single value CSV Date: Tue, 17 Feb 2004 21:04:38 +0000 User-Agent: KMail/1.5 References: <007701c3f591$5acc3020$2766f30a@development.greatgulfhomes.com> In-Reply-To: <007701c3f591$5acc3020$2766f30a@development.greatgulfhomes.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200402172104.38307.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/228 X-Sequence-Number: 16918 On Tuesday 17 February 2004 20:05, terry@ashtonwoodshomes.com wrote: > I should probably be punished for even asking this question, but a > simplified version of what I want is this... > > I have 2 tables: > floorplans > floorplan_id | description > -------------------------- > 2240 | test floorplan > > and a table elevations > floorplan_id | elevation > ------------------------ > 2240 | A > 2240 | B > 2240 | C > > I want to perform a query that returns this result set: > baseplan_id | elevations > 2240 | A,B,C You've got two options here: 1. Write a set-returning function in plpgsql (or whatever) to do your looping and build the CSV value. Perhaps look in the contrib/ folder too - might be something in the tablefunc section. 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. You can find info on both in the archives, probably with examples. Also - check techdocs. -- Richard Huxton Archonet Ltd