pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Josh Berkus <josh@agliodbs.com>
To: sqllist <pgsql-sql@postgresql.org>
Subject: List Concatination
Date: Thu, 08 Mar 2001 21:17:27 -0800
Message-ID: <3AA86767.698DDFFF@agliodbs.com> (raw)

Folks,

	I have an interesting problem.  For purpose of presentation to users,
I'd like to concatinate a list of VARCHAR values from a subtable.  To
simplify my actual situation:

CREATE TABLE clients (
	client_id SERIAL PRIMARY KEY,
	client_name VARCHAR(50) );

CREATE TABLE client_contacts (
	contact_id SERIAL PRIMARY KEY,
	client_id REFERENCES clients(client_id),
	first_name VARCHAR(25),
	last_name VARCHAR(25) );

CLients:
1 	McMurphy Assoc.
2	Ross Construction

Contacts
1	1	Jim	Henson
2	1	Pat	O'Gannet
3	2	Sara	Vaugn
3	2	Bill	Murray

etc.

What I'd like to be able to do is present a list of clients and their
comma-seperated contacts in paragraph form, hence:


Client			Contacts
McMurphy Assoc.		Jim Henson, Pat O'Gannet, Kelley Moore

Ross Construction	Sara Vaugn, Bill Murray, Peter Frump,
			Siskel Ebert

I can figure out how to do this procedurally (using PL/pgSQL and a
cursor) but not how to do it declaratively (using only SQL).  The reason
it's important to do it declaritively is that there are actually two
sub-tables with thousands of entries and the procedural approach is
rather slow.

Suggestions?

						-Josh Berkus

-- 
______AGLIO DATABASE SOLUTIONS___________________________
                                        Josh Berkus
   Complete information technology      josh@agliodbs.com
    and data management solutions       (415) 565-7293
   for law firms, small businesses       fax  621-2533
    and non-profit organizations.       San Francisco



view thread (10+ messages)  latest in thread

Message-ID: <3AA86767.698DDFFF@agliodbs.com>
Permalink:  ../3AA86767.698DDFFF@agliodbs.com/
Also on:    postgresql.org/message-id/3AA86767.698DDFFF@agliodbs.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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: josh@agliodbs.com
  Subject: Re: List Concatination
  In-Reply-To: <3AA86767.698DDFFF@agliodbs.com>
  References: <3AA86767.698DDFFF@agliodbs.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