How to convert rows into column while inserting into temp table?

89 views Asked by At

I want to convert rows into column while inserting into temp table. I read somewhere about crosstab but not exactly sure how to use it for my purpose.

So suppose firstly I query like

select cat_id, category_name from category_tab;

cat_id        category_name

111              books    

112              pen

113              copy    

Now I want a temp table which should be like

  s_no        books       pen      copy

   1                 

   2             

   3               

s_no will be serial number and rows of previous query becomes the column in new temp table.

How can I achieve this task in postgres ?

0

There are 0 answers