I am trying to change the column order in the table of postgressql. But I didn\'t get any clue or answer. I think this functionality is add in new version. I am using postgres
You would have to drop and re-create the table or at least the lastname
column for that:
BEGIN;
ALTER TABLE atable RENAME lastname TO oldcol;
ALTER TABLE atable ADD lastname text NOT NULL;
UPDATE atable SET lastname = oldcol;
ALTER TABLE atable DROP oldcol;
COMMIT;
But the exercise is pretty pointless, since you can always determine the order in which you get the columns in the SELECT
clause. You aren't using SELECT *
, are you? That would be problematic for other reasons as well; it is only useful for ad-hoc queries.