add columns after another in postgresql

1

I would like to know if there is a way to add columns later after a certain column in postgre, as in mysql that aría in this way

alter table personal add capital int not null after nom;

I would like to know if there is any way in postgresql

    
asked by Alejandro.C 06.12.2017 в 23:10
source

2 answers

1

Can not. In postgres the new columns always go to the end.

According to the wiki, there are two workarounds :

  • Recreate the table
  • Add N auxiliary columns (leaving your new column between them, in the desired position), copy the data to those auxiliary columns, and delete the original columns.

As you can see, neither of the two solutions is very beautiful.

    
answered by 06.12.2017 в 23:21
0

If the table has no information, just truncate and create again in the order you want the fields to be. If the table has many records, create a new auxiliary table and pass the information to this new auxiliary table, truncate the table that does not have the fields order and create again in the order you need, pass the records of the auxiliary table to the table already with the ordered columns, truncates the auxiliary table, ready.

    
answered by 07.12.2017 в 00:04