Can you please help me how to write SQL query or syntax for cross-tab function in Postgresql.
NOTE : want to do the transpose of columns by keeping the two three columns constant.
Below is my input table :
|Col A||Col B||Col C||Col D||Col E||Col F||Col G||Col H|
Below should be my output table :
|Col A||Col B||Col Name||Col Value|
Values willl be repeated as same for 444,555,666.
Hope you are doing good.
We kindly request you to please refer following link for query formation for cross-tab function.
Pleaes let us know if you face any issue.
Unfortunately, crosstab doesn't dynamically aggregate many columns into one, as it seems that you are trying to do (with the added difficulty of providing a label ("Col Name") identifying its source column). You'll need to do some combination of row_to_json (to capture column names) and json_agg (to combine the values together). Unless you absolutely need to do it on the database side, it might actually be easier to aggregate the columns using software/code.
Hi @richyen ,
Can you please help me out how to write the Software/ Code on database side to perform this action or with combination of row_to_json (to capture column names) and json_agg (to combine the values together).
If you can give me more input from yourside, it might be really helpful for building the Application.
I was following the same URL which you mentioned, by doing the custom wrappers but unable to execute the syntax.
If you can give me more input that might be really helpful for me.
Can you please give your inputs on above mentioned request.