This is currently not possible. You have to drop and recreate the table.
Theoretically you could add the column, drop and re-add all other columns, but that's hardly practical.
It's an ongoing discussion and an open TODO-item of the Postgres project to allow reordering of columns. But a lot of dependencies and related considerations make that hard.
Quoting the Postgres project's ToDo List:
Allow column display reordering by recording a display, storage, and
permanent id for every column?
Contrary to what some believe, the order of columns in a table is not irrelevant, for multiple reasons.
- The default order is used for statements like
INSERT
without column definition lists.
Or SELECT *
, which returns columns in the predefined order.
- The composite type of the table uses the same order of columns.
- The order of columns is relevant for storage optimization (padding and alignment matter). More:
People may be confusing this with the order of rows, which in undefined in a table.