Re: concatenate text

From: Michael Fuhr <mike(at)fuhr(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 02:00:21
Message-ID: 20050905020021.GA64260@winnie.fuhr.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.

Are you looking for an aggregate in particular or will any solution
suffice? Here's a trivial example that works in 7.4 and later:

CREATE TABLE foo (name text);

INSERT INTO foo VALUES ('Alice');
INSERT INTO foo VALUES ('Bob');
INSERT INTO foo VALUES ('Carol');
INSERT INTO foo VALUES ('Dave');

SELECT array_to_string(ARRAY(SELECT name FROM foo), '');
array_to_string
-------------------
AliceBobCarolDave
(1 row)

If you need an aggregate then search the archives; examples have
been posted before.

--
Michael Fuhr

In response to

Browse pgsql-general by date

  From Date Subject
Next Message David Fetter 2005-09-05 03:12:23 Re: concatenate text
Previous Message Allan Wang 2005-09-05 00:39:22 Re: concatenate text