Concatenate strings using GROUP BY - Mailing list pgsql-sql

From Philippe Lang
Subject Concatenate strings using GROUP BY
Date
Msg-id 6C0CF58A187DA5479245E0830AF84F42143B77@poweredge.attiksystem.ch
Whole thread Raw
Responses Re: Concatenate strings using GROUP BY  ("A. Kretschmer" <andreas.kretschmer@schollglas.com>)
List pgsql-sql
Hi,

Let's say we have a query like:

SELECT id, fk, str 
FROM foo

... which returns:

id    fk    str
---------------
1     1     a
2     1     b
3     2     c

Is there a pure SQL way of contactenating str values into a single string,
and get instead:

id    fk    str
---------------
1     1     a/b
2     12    c

I was thinking of something like:

SELECT id, fk, CONCAT(str || '/')
FROM FOO
GROUP BY fk

Do we have to use PL/PGSQL for that?

Thanks,


----------------------------------
Philippe Lang, Ing. Dipl. EPFL
Attik System
rte de la Fonderie 2
1700 Fribourg
Switzerland
http://www.attiksystem.ch

Tel:      +41 (26) 422 13 75 
Fax:      +41 (26) 422 13 76
Email:    philippe.lang@attiksystem.ch

pgsql-sql by date:

Previous
From: Patrick JACQUOT
Date:
Subject: Re: Non Matching Records in Two Tables
Next
From: "A. Kretschmer"
Date:
Subject: Re: Concatenate strings using GROUP BY