Re: plpgsql, I have a solution, want to see if there is a cleaner/better one. Taking vertical list and comma separating it onto a row

From: Thomas Kellerer <spam_eater(at)gmx(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: plpgsql, I have a solution, want to see if there is a cleaner/better one. Taking vertical list and comma separating it onto a row
Date: 2011-11-10 13:34:47
Message-ID: j9gjs4$bvn$1@dough.gmane.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Henry Drexler, 10.11.2011 14:22:
> I am thinking there is a better/simpler way, though this is what I have working:
>
> (postgres 9.1)
>
>
> I would like to have the list of colors for each type of clothing to be comma seperated in the end result.
>
> like this:
>
> type organized_by_type
> pants red, blue, orange
> shirt black, gray

> CREATE TABLE clothes
> (
> type character varying,
> color character varying
> )

SELECT type,
string_agg(color, ',') as organized_by_type
FROM clothes
GROUP BY type;

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Henry Drexler 2011-11-10 13:42:08 Re: Re: plpgsql, I have a solution, want to see if there is a cleaner/better one. Taking vertical list and comma separating it onto a row
Previous Message Alban Hertroys 2011-11-10 13:28:28 Re: dll files missing in postgrsql bin folder in Windows