Forum OpenACS Q&A: Response to How to drop a column in postgres ?

Collapse
Posted by Reuven Lerner on

This is in the PostgreSQL FAQ:

4.4) How do you remove a column from a table?

We do not support ALTER TABLE DROP COLUMN, but do this:

    BEGIN;
    LOCK TABLE old_table;
    SELECT ...  -- select all columns but the one you want to remove
    INTO TABLE new_table
    FROM old_table;
    DROP TABLE old_table;
    ALTER TABLE new_table RENAME TO old_table;
    COMMIT;

Yes, this is annoying. According to the to do list, it looks like this will be fixed in the upcoming 7.3 release.