Is it possible to change the natural order of columns in Postgres?

后端 未结 8 1746
既然无缘
既然无缘 2020-12-05 13:25

Is it possible to change the natural order of columns in Postgres 8.1?

I know that you shouldn\'t rely on column order - it\'s not essential to what I am do

8条回答
  •  再見小時候
    2020-12-05 14:01

    If your database is not very big and you can afford some downtime then you can:

    1. Disable write access to the database
      this is essential as otherwise any changes after starting the next point will be lost
    2. pg_dump --create --column-inserts databasename > databasename.pgdump.sql
    3. Edit apropriate CREATE TABLE statement in databasename.pgdump.sql
      If the file is too big for your editor just split it using split command, edit, then assemble back using cat
    4. drop database databasename
      You do have a recent backup, just in case, do you?
    5. psql --single-transaction -f databasename.pgdump.sql
      If you don't use --single-transaction it will be very slow

    If you use so called large objects make sure they are included in the dump. I'm not sure if they are by default in 8.1.

提交回复
热议问题