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 17F55D1BB5E for ; Tue, 17 Feb 2004 20:07:10 +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 17673-10 for ; Tue, 17 Feb 2004 16:07:07 -0400 (AST) Received: from mail.greatgulfhomes.com (unknown [216.94.125.243]) by svr1.postgresql.org (Postfix) with ESMTP id 47653D1B57C for ; Tue, 17 Feb 2004 16:07:05 -0400 (AST) Received: from terrynew2 (firewall.development.greatgulfhomes.com [216.191.203.106]) by mail.greatgulfhomes.com (Postfix) with SMTP id 9685536695C for ; Tue, 17 Feb 2004 15:10:08 -0500 (EST) From: To: "Postgresql Sql Group (E-mail)" Subject: Return relation table data in a single value CSV Date: Tue, 17 Feb 2004 15:05:12 -0500 Message-ID: <007701c3f591$5acc3020$2766f30a@development.greatgulfhomes.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook 8.5, Build 4.71.2173.0 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2615.200 Importance: Normal X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200402/224 X-Sequence-Number: 16914 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 The real query is, of course, *much* more complex then that, as there are many more fields in floorplans, and floorplans is joined to other tables. Currently I return my floorplan information, then perform a second query to get the elevation records, and loop over the second query to compile the comma separated list of elevations. I have tried subselects concatenated with basically || ',' || where each subselect does an OFFSET X LIMIT 1, and the ',' is wrapped with a case statement to hide the comma if there are no further elevations. It gets very messy very fast as and further I end up hard coding the max number of elevations. Any ideas? Terry Fielder Manager Software Development and Deployment Great Gulf Homes / Ashton Woods Homes terry@greatgulfhomes.com Fax: (416) 441-9085