From: | Richard Huxton <dev(at)archonet(dot)com> |
---|---|
To: | <terry(at)ashtonwoodshomes(dot)com>, "Postgresql Sql Group (E-mail)" <pgsql-sql(at)postgresql(dot)org> |
Subject: | Re: Return relation table data in a single value CSV |
Date: | 2004-02-17 21:04:38 |
Message-ID: | 200402172104.38307.dev@archonet.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
On Tuesday 17 February 2004 20:05, terry(at)ashtonwoodshomes(dot)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
From | Date | Subject | |
---|---|---|---|
Next Message | scott.marlowe | 2004-02-17 22:46:52 | Re: Function |
Previous Message | Richard Huxton | 2004-02-17 20:26:41 | Re: SQL query seach + rearranging results |