I have a table with key and value and I have saved the values as shown below
when I use the below query
select * from crosstab ( 'select rowname,colname,max(cellval) from table_to_pivot group by 1,2 order by 1,2', 'select distinct colname from table_to_pivot order by 1' ) as newtable (rowname varchar,_col1 integer,_col2 integer,_col3 integer);
I am getting my desired output as shown below
but I don't want to define the column names [_col1 integer,_col2 integer,_col3 integer] in my query, I want it to be dynamic. Is there a way to achieve this?