pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Philippe Lang <philippe.lang@attiksystem.ch>
To: pgsql-sql@postgresql.org
Subject: Concatenate strings using GROUP BY
Date: Thu, 9 Feb 2006 10:35:03 +0100
Message-ID: <6C0CF58A187DA5479245E0830AF84F42143B77@poweredge.attiksystem.ch> (raw)

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

Attachments:

  smime.p7s (application/x-pkcs7-signature, 3.1K) download

view thread (2+ messages)  latest in thread

Message-ID: <6C0CF58A187DA5479245E0830AF84F42143B77@poweredge.attiksystem.ch>
Permalink:  ../6C0CF58A187DA5479245E0830AF84F42143B77@poweredge.attiksystem.ch/
Also on:    postgresql.org/message-id/6C0CF58A187DA5479245E0830AF84F42143B77@poweredge.attiksystem.ch

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: philippe.lang@attiksystem.ch
  Subject: Re: Concatenate strings using GROUP BY
  In-Reply-To: <6C0CF58A187DA5479245E0830AF84F42143B77@poweredge.attiksystem.ch>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox