Welcome Guest! Log in
×

Notice

The forum is in read only mode.
Stambia versions 2.x, 3.x, S17, S18, S19 and S20 are reaching End of Support January, 15th, 2024. Please consider upgrading to the supported Semarchy xDI versions. See Global Policy Support and the Semarchy Documentation.

The Stambia User Community is moving to Semarchy! All the applicable resources have already been moved or are currently being moved to their new location. Read more…

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.