Skip site navigation (1) Skip section navigation (2)

Multiple rows into one row

From: Raimon <coder(at)montx(dot)com>
To: PostgreSQL Novice <pgsql-novice(at)postgresql(dot)org>
Subject: Multiple rows into one row
Date: 2008-02-02 15:13:20
Message-ID: (view raw or whole thread)
Lists: pgsql-novice

I can't find any reference in PostgreSQL documentation, if this is  

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

So I could issue a SELECT like this:

SELECT, (SELECT name FROM animals WHERE customer_id = AS animals FROM customer

name	animals
-------	-----------
Peter 	dog,cat
Lisa		turtle
Anthony	bird,elephant

I could find info about PIVOT and some other extra functionalities  
from other databases like Oracle, SQL server, ...



In response to


pgsql-novice by date

Next:From: Mike EllsworthDate: 2008-02-02 15:54:26
Subject: Re: Multiple rows into one row
Previous:From: Robert M. BernabeDate: 2008-02-01 16:20:33
Subject: Re: Group Roles are now Login Roles in pgAdmin?

Privacy Policy | About PostgreSQL
Copyright © 1996-2015 The PostgreSQL Global Development Group