Re: Multiple rows into one row

From: "A(dot) Kretschmer" <andreas(dot)kretschmer(at)schollglas(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: Re: Multiple rows into one row
Date: 2008-02-02 16:04:36
Message-ID: 20080202160436.GA32408@a-kretschmer.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

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

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Aílsom F. Heringer 2008-02-02 17:36:42 first message: SELECT <column> FROM <table>
Previous Message Mike Ellsworth 2008-02-02 15:54:26 Re: Multiple rows into one row