A table's columns may be safely re-named in PostgreSQL without modifying the data which is represented in that table. Re-naming a column can obviously be a dangerous thing to do, however, if existing applications rely on an existing identifier.

The following syntax describes how to re-name a column where table_name is the name of the table being renamed, column_name is the current name of the column, and new_column_name is the intended new name for the column:

  ALTER TABLE table_name
        RENAME COLUMN column_name TO new_column_name;

As with the other ALTER TABLE commands, the COLUMN keyword is considered noise, and may be optionally omitted. The existence of two identifiers separated by the TO keyword are enough for PostgreSQL to determine that you are requesting a column re-name, and not a table re-name. This is demonstrated in Example 4-10 .

Example 4-10. Re-naming a Column

booktown=# \d daily_inventory
    Table "daily_inventory"
 Attribute |  Type   | Modifier
-----------+---------+----------
 isbn      | text    |
 in_stock  | boolean |
 
booktown=# ALTER TABLE daily_inventory
booktown-#       RENAME COLUMN in_stock TO is_in_stock;
ALTER
booktown=# ALTER TABLE daily_inventory
booktown-#       RENAME is_in_stock TO is_stocked;
ALTER