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>
Cc: josh@agliodbs.com
Subject: Re: List Concatination
Date: Fri, 09 Mar 2001 08:45:43 -0800
Message-ID: <web-22750@davinci.ethosmedia.com> (raw)
In-Reply-To: <6972.984155124@sss.pgh.pa.us>

Tom, Richard,

	Thanks for the advice, guys!  This being Postgres, I *knew* there would
be other options.

> > create aggregate catenate(sfunc1=textcat, basetype=text,
> stype1=text, initcond1='');
> 
> > Then group by client and catenate(firstname || ' ' || lastname)
> 
> With a custom aggregate you could make the aggregate function
> responsible for handling the ordering of contacts:
> 
>  select client, contactlist(contact) from table group by client;
> 
> If I were doing this, I'd make the aggregate state variable be "array
> of
> text", and have the transition function simply append each new value
> to
> the array.  (Or, if you're willing to assume that no newlines appear
> in
> the contact names, the state variable can be plain text and can list
> the
> contacts one per line.)  Then the finalization function would sort
> the
> array elements and concatenate them with inserted commas.  These two
> functions would be pretty trivial to write in pltcl or plperl, either
> of which are the tool of first choice for string-bashing problems.

	Hmmm... neither of these options sounds like it would be faster and
more scalable than a simple PL/pgSQL function which loops throught the
names and appends them to a string.  Perhaps for Phase II of our project
I'll be able to afford somebody to write a custom aggregate in C.

					-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: <web-22750@davinci.ethosmedia.com>
Permalink:  ../web-22750@davinci.ethosmedia.com/
Also on:    postgresql.org/message-id/web-22750@davinci.ethosmedia.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: <web-22750@davinci.ethosmedia.com>
  References: <6972.984155124@sss.pgh.pa.us> <web-22750@davinci.ethosmedia.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