In my PostgreSQL database:
select index from sample;
index
---------
1
2
3
1
2
I want to place the index
as below:
select index from sample;
index
---------
1
2
3
4
5
Saddam Khan provided a way to solve it:
alter table sample add column sort_id serial;
-- Drop column index from sample table.
alter table sample drop column index;
-- Rename column sort_id to index in sample table
alter table sample rename column sort_id to index;
-- Add Primary Key.
alter table sample add primary key(index);
But now,the index
column is at the right side (end of the table). How can I place it at the left side?
select * from sample;
ticker | roe | income | index
--------+---------+---------+-------
000820 | 2347.63 | 120.16 | 1
300071 | 676.52 | 1035.38 | 2
002188 | 289.69 | 273.95 | 3
600734 | 151.58 | 921.82 | 4
000523 | 139.94 | 2585.55 | 5
600078 | 138.28 | 3333.41 | 6