Search code examples
postgresqlpivotcrosstab

Postgresql: pivoting a column without crosstab


i've tried to pivot a column in a concatenation of string i see is possible with crosstab but i can't install tablefunc. i've a list of tables and columns name what obtain from the following query

SELECT 
 table_name
, column_name
FROM 
   information_schema.columns


 table_name| column_name
     tab_1 |id
      tab_1|email
      tab_2|field_1
       tab2|field_2

What i want obtain is :

 table_name| column_name
      tab_1|id, email
      tab_2|field_1, field_2

Thank you for your help.


Solution

  • I think that you want string aggregation:

    select table_name, string_agg(column_name, ', ') column_name
    from information_schema.columns
    group by table_name