postgres reorder columns

Solutions on MaxInterview for postgres reorder columns by the best coders in the world

showing results for - "postgres reorder columns"
Lowell
19 May 2020
1    PostgreSQL currently defines column order based on the attnum column of the pg_attribute table. The only way to change column order is either by recreating the table, or by adding columns and rotating data until you reach the desired layout.
2    
3    ----
4    
5    CREATE VIEW original_tab_vw AS
6    SELECT a.col1, a.col3, a.col4, a.col2
7    FROM original_tab a
8    WHERE a.col1 IS NOT NULL --or whatever
9