Welcome Guest! Log in

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
Off Topic : rows to col in PostgreSQL was created by Nicolas Verscheure
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.

Please Log in or Create an account to join the conversation.