Welcome Guest! Log in
×

Notice

The forum is in read only mode.
Due to some maintenance operations, stambia.org will be switched to read-only mode during the 13th November. It will be possible to read and download, but impossible to post on the forums or create new accounts. For any question please contact the support team.

Topic-icon Idea Off Topic : rows to col in PostgreSQL

  • Nicolas Verscheure
  • Nicolas Verscheure's Avatar Topic Author
  • Offline
More
17 Dec 2014 16:09 - 18 Dec 2014 14:44 #1 by Nicolas Verscheure
Nicolas Verscheure created the topic: Off Topic : rows to col in PostgreSQL
Sometimes, it's really usefull to transform rows into a column.
It's very easy in PostgreSQL with string_agg function :

select 
  cus.customer_key
, cus.first_name
, cus.last_name
, select string_agg(card.card_key, ',') from customer_cards card where card.customer_key = cus.customer_key
from
  customers cus;

For more informations about functions aggregate in PostgreSQL, consult the official documentation .

Another tip, if you want to know the version of PostgreSQL :

select version();
Last Edit: 18 Dec 2014 14:44 by Nicolas Verscheure.