Re: concatenate text

From: David Fetter <david(at)fetter(dot)org>
To: Sterpu Victor <victor(at)ambra(dot)ro>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: concatenate text
Date: 2005-09-05 03:12:23
Message-ID: 20050905031223.GD11713@fetter.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, Sep 05, 2005 at 03:00:30AM +0300, Sterpu Victor wrote:
> Can I do something like this?
> SELECT sum(name) FROM table;
>
> Where name is a text field.
> I know 'sum' doesn't work, but is there another solution?
> '||' is not good because it will take just 2 arguments.

Currently, you can use a custom aggregate like array_accum()
http://www.postgresql.org/docs/current/static/xaggr.html

combined with the array_to_string() like this:

SELECT array_to_string(array_accum(email), ', ') AS "emails"
FROM person_email;

Hope this helps :)

Cheers,
D
--
David Fetter david(at)fetter(dot)org http://fetter.org/
phone: +1 510 893 6100 mobile: +1 415 235 3778

Remember to vote!

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tony Caduto 2005-09-05 03:40:50 Re: Embed PostgreSQL in application
Previous Message Michael Fuhr 2005-09-05 02:00:21 Re: concatenate text