Re: Multiple rows into one row

From: Raimon <coder(at)montx(dot)com>
To: PostgreSQL Novice <pgsql-novice(at)postgresql(dot)org>
Subject: Re: Multiple rows into one row
Date: 2008-02-02 18:42:24
Message-ID: 52BF50D9-D560-476A-B6D6-7842E9B11309@montx.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

thanks !

r.

On 02/02/2008, at 17:04, A. Kretschmer wrote:

> am Sat, dem 02.02.2008, um 16:13:20 +0100 mailte Raimon folgendes:
>> Hello,
>>
>> I can't find any reference in PostgreSQL documentation, if this is
>> possible:
>>
>> I want to have some rows in one column, with the values separated for
>> example by a comma.
>>
>> SELECT name FROM animals WHERE customer_id = '5'
>>
>> - cat
>> - dog
>> - turtle
>>
>> I would like to have this like this:
>>
>> - cat, dog, turtle
>
> test=*# select * from animals ;
> id | name
> ----+--------
> 5 | cat
> 5 | dog
> 5 | turtle
> (3 rows)
>
> test=*# select array_to_string(array(select name from animals where
> id=5), ', ');
> array_to_string
> ------------------
> cat, dog, turtle
>
>
> HTH, Andreas
> --
> Andreas Kretschmer
> Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: -> Header)
> GnuPG-ID: 0x3FFF606C, privat 0x7F4584DA http://wwwkeys.de.pgp.net
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 5: don't forget to increase your free space map settings
>

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Didier Gasser-Morlay 2008-02-03 08:26:34 Where clause...
Previous Message Raimon 2008-02-02 18:38:25 Re: Multiple rows into one row