Search Postgresql Archives

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 Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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;



--
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux