Received: from davinci.ethosmedia.com (davinci.ethosmedia.com [209.10.40.250]) by mail.postgresql.org (8.11.1/8.11.1) with ESMTP id f29Gjmx82178 for ; Fri, 9 Mar 2001 11:45:49 -0500 (EST) (envelope-from josh@agliodbs.com) Received: from [209.10.40.250] (account ) by davinci.ethosmedia.com (CommuniGate Pro WebUser 3.4.1) with HTTP id 22750; Fri, 09 Mar 2001 08:45:43 -0800 From: "Josh Berkus" Subject: Re: List Concatination To: sqllist Cc: josh@agliodbs.com X-Mailer: CommuniGate Pro Web Mailer v.3.4.1 Date: Fri, 09 Mar 2001 08:45:43 -0800 Message-ID: In-Reply-To: <6972.984155124@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 8bit X-Archive-Number: 200103/196 X-Sequence-Number: 1850 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