Thread: Reordering columns

Reordering columns

From
pgadmin@weevil.net
Date:
Howdy,

I was thinking of adding a feature to pgadmin3, and I just wanted to
make sure there wasn't already someone working on it to avoid
duplicating effort.

It would be really nice to be able to either reorder the columns of a
table or insert a new column at an arbitrary position.  While PostgreSQL
doesn't support this as such, you can achieve the same effect by:

- Renaming the original table and all its constraints & triggers
- Creating a new table with the desired schema
- Inserting everything from the renamed old table into the new table
- Re-creating the constraints & triggers
- Dropping the old table, old constraints, and old triggers

At one of my previous jobs, I used an awesome tool called DBArtisan that
did exactly this (we use Sybase, which has [or had] the same limitation
as PostgreSQL of not natively supporting reordering of table columns).
If you added a new column at the end of a table, it would simply issue
an ALTER TABLE command, but if you added one in the middle, or reordered
existing columns, it would build a query as I've described above.

Any thoughts, suggestions, criticisms would be appreciated.

Cheers,
Tony

--
(lambda x. x x) (lambda x. x x)