Re: concatenate text - Mailing list pgsql-general

From Michael Fuhr
Subject Re: concatenate text
Date
Msg-id 20050905020021.GA64260@winnie.fuhr.org
Whole thread Raw
In response to concatenate text  (Sterpu Victor <victor@ambra.ro>)
List 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

pgsql-general by date:

Previous
From: Tony Caduto
Date:
Subject: Re: Embed PostgreSQL in application
Next
From: Allan Wang
Date:
Subject: Re: concatenate text