pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Josh Berkus <josh@agliodbs.com>
Cc: sqllist <pgsql-sql@postgresql.org>
Subject: Re: List Concatination
Date: Thu, 15 Mar 2001 08:29:50 -0800
Message-ID: <3AB0EDFE.998C387C@agliodbs.com> (raw)
References: <3AA86767.698DDFFF@agliodbs.com>
	<3AA8BB73.5647B248@archonet.com>

Richard,

	I wanted to thank you for the concatination suggestion ... on testing,
a custom aggregate *was* faster than procedural concatination ... much
faster.

> But - if you don't care about the order of contacts you can define an
> aggregate function:
> 
> create aggregate catenate(sfunc1=textcat, basetype=text, stype1=text, initcond1='');
> 
> Then group by client and catenate(firstname || ' ' || lastname)
> 
> You'll want to read the CREATE AGGREGATE page in the reference manual,
> replace textcat with your own routine that adds a comma and you'll need
> a finalisation routine to strip the final trailing comma.

Actually, if you use a sub-select as your data source, you can control
both the appearance and the order of the catenated values:

SELECT client, catenate(con_name)
FROM (SELECT client, (firstname || ' ' || lastname || ', '
	FROM contacts ORDER BY lastname ASC) AS con_list
GROUP BY client;

This seems to work pretty well.

> Note that this is probably not a good idea - the ordering of the
> contacts will not be well-defined. When I asked about this Tom Lane was
> quite surprised that it worked, so no guarantees about long-term suitability.

Hmmm ... this feature is very, very, useful now that I know how to use
it.  I'd love to see it hang around for future versions of PgSQL.  Tom?

-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: <3AB0EDFE.998C387C@agliodbs.com>
Permalink:  ../3AB0EDFE.998C387C@agliodbs.com/
Also on:    postgresql.org/message-id/3AB0EDFE.998C387C@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: <3AB0EDFE.998C387C@agliodbs.com>
  References: <3AA86767.698DDFFF@agliodbs.com> <3AA8BB73.5647B248@archonet.com> <3AB0EDFE.998C387C@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