1

how to re-arrange the column names in PostgreSQL table with records

entityid formattedfilename 
-------- ----------------- 
1        file1             
2        file2  

Re-arrange below format with record

formattedfilename entityid 
----------------- -------- 
file1             1        
file2             2   
Vivek S.
  • 17,862
  • 6
  • 63
  • 80

2 Answers2

0

You can create a VIEW for this,
see following demo

create table foo (entityid int,formattedfilename text);

insert into foo values (1,'file1');
insert into foo values (2,'file2');

select * from foo

RESULT

entityid formattedfilename 
-------- ----------------- 
1        file1             
2        file2             

Now create a view like below

create or replace view vfoo as 
select formattedfilename,entityid from foo .

select * from vfoo

RESULT

formattedfilename entityid 
----------------- -------- 
file1             1        
file2             2  

Still you want to do it with the table itself then refer : https://wiki.postgresql.org/wiki/Alter_column_position

Vivek S.
  • 17,862
  • 6
  • 63
  • 80
-1

Just select it something like:

SELECT formattedfilename, entityid
FROM mytable

if you want SELECT * should return you that format then i would say you better have a view over your table and query on view.

SMA
  • 35,277
  • 7
  • 46
  • 71