Re: Concatenate strings using GROUP BY

From: "A(dot) Kretschmer" <andreas(dot)kretschmer(at)schollglas(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: Concatenate strings using GROUP BY
Date: 2006-02-09 09:52:56
Message-ID: 20060209095256.GD2458@webserv.wug-glas.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

am 09.02.2006, um 10:35:03 +0100 mailte Philippe Lang folgendes:
> 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?

Yes, you need a new aggregate function.
http://www.postgresql.org/docs/8.0/interactive/xaggr.html

HTH, Andreas
--
Andreas Kretschmer (Kontakt: siehe Header)
Heynitz: 035242/47215, D1: 0160/7141639
GnuPG-ID 0x3FFF606C http://wwwkeys.de.pgp.net
=== Schollglas Unternehmensgruppe ===

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Richard Huxton 2006-02-09 10:25:59 Re: Column Index vs Record Insert Trade-off?
Previous Message Philippe Lang 2006-02-09 09:35:03 Concatenate strings using GROUP BY