Re: List Concatination

From: "Josh Berkus" <josh(at)agliodbs(dot)com>
To: sqllist <pgsql-sql(at)postgresql(dot)org>
Cc: josh(at)agliodbs(dot)com
Subject: Re: List Concatination
Date: 2001-03-09 16:45:43
Message-ID: web-22750@davinci.ethosmedia.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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(at)agliodbs(dot)com
and data management solutions (415) 565-7293
for law firms, small businesses fax 621-2533
and non-profit organizations. San Francisco

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Josh Berkus 2001-03-09 16:49:08 Re: cannot get CREATE TABLE AS to work
Previous Message Tom Lane 2001-03-09 16:42:39 Re: from PosgreSQL 7.1b3 to 7.0.3