Re: List Concatination - Mailing list pgsql-sql

From Josh Berkus
Subject Re: List Concatination
Date
Msg-id web-22750@davinci.ethosmedia.com
Whole thread Raw
In response to Re: List Concatination  (Tom Lane <tgl@sss.pgh.pa.us>)
List 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
informationtechnology      josh@agliodbs.com  and data management solutions       (415) 565-7293 for law firms, small
businesses       fax 621-2533   and non-profit organizations.      San Francisco
 


pgsql-sql by date:

Previous
From: Peter Eisentraut
Date:
Subject: Re: cannot get CREATE TABLE AS to work
Next
From: "Josh Berkus"
Date:
Subject: Re: cannot get CREATE TABLE AS to work