pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Richard Huxton <dev@archonet.com>
To: terry@ashtonwoodshomes.com
To: Postgresql Sql Group (E-mail) <pgsql-sql@postgresql.org>
Subject: Re: Return relation table data in a single value CSV
Date: Tue, 17 Feb 2004 21:04:38 +0000
Message-ID: <200402172104.38307.dev@archonet.com> (raw)
In-Reply-To: <007701c3f591$5acc3020$2766f30a@development.greatgulfhomes.com>
References: <007701c3f591$5acc3020$2766f30a@development.greatgulfhomes.com>

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



view thread (4+ messages)  latest in thread

Message-ID: <200402172104.38307.dev@archonet.com>
Permalink:  ../200402172104.38307.dev@archonet.com/
Also on:    postgresql.org/message-id/200402172104.38307.dev@archonet.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: dev@archonet.com, terry@ashtonwoodshomes.com
  Subject: Re: Return relation table data in a single value CSV
  In-Reply-To: <200402172104.38307.dev@archonet.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox