Re: Return relation table data in a single value CSV - Mailing list pgsql-sql

From Richard Huxton
Subject Re: Return relation table data in a single value CSV
Date
Msg-id 200402172104.38307.dev@archonet.com
Whole thread Raw
In response to Return relation table data in a single value CSV  (<terry@ashtonwoodshomes.com>)
Responses Re: Return relation table data in a single value CSV
List pgsql-sql
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


pgsql-sql by date:

Previous
From: Richard Huxton
Date:
Subject: Re: FW: Function
Next
From: "scott.marlowe"
Date:
Subject: Re: Function