Renaming a column in PostgreSQL is done with the ALTER TABLE ... RENAME COLUMN statement. Unlike some schema changes, this operation is safe for dependent objects: PostgreSQL automatically cascades the rename to views, foreign key constraints, triggers, and stored procedures that reference the column.
Basic syntax
The full syntax to rename a column is:
ALTER TABLE table_name
RENAME COLUMN column_name TO new_column_name;
The COLUMN keyword is optional, so this shorter form also works:
ALTER TABLE table_name
RENAME column_name TO new_column_name;
To rename multiple columns, run separate statements — there is no single-statement shortcut for multiple renames:
ALTER TABLE customers RENAME COLUMN name TO customer_name;
ALTER TABLE customers RENAME COLUMN phone TO contact_phone;
If the column does not exist, PostgreSQL raises an error. There is no IF EXISTS option for the RENAME COLUMN clause.
Practical examples
First, set up sample tables including a view that references a column you will rename:
CREATE TABLE customer_groups (
id SERIAL PRIMARY KEY,
name VARCHAR NOT NULL
);
CREATE TABLE customers (
id SERIAL PRIMARY KEY,
name VARCHAR NOT NULL,
phone VARCHAR NOT NULL,
email VARCHAR,
group_id INT,
FOREIGN KEY (group_id) REFERENCES customer_groups (id)
);
CREATE VIEW customer_data AS
SELECT c.id, c.name, g.name AS customer_group
FROM customers c
INNER JOIN customer_groups g ON g.id = c.group_id;
Rename the email column of the customers table:
ALTER TABLE customers RENAME COLUMN email TO contact_email;
Now rename the name column in customer_groups, which is referenced by the customer_data view:
ALTER TABLE customer_groups RENAME COLUMN name TO group_name;
PostgreSQL automatically updates the view definition. Inspecting the view confirms the cascade:
d+ customer_data
-- Output:
-- View definition:
-- SELECT c.id, c.name, g.group_name AS customer_group
-- FROM customers c
-- JOIN customer_groups g ON g.id = c.group_id;
Production tips
- Column renames are metadata-only operations in PostgreSQL — they do not rewrite table data and are very fast even on large tables.
- PostgreSQL acquires an
ACCESS EXCLUSIVElock during the rename, which blocks reads and writes briefly. Run renames during low-traffic windows for busy tables. - Update application code, ORM models, and query strings before or immediately after the rename to avoid runtime errors.
- Use
pg_dependord+ view_nameto audit dependent objects before and after renaming to confirm cascade behaviour. - In migration frameworks, pair the rename with a corresponding rollback that renames the column back to the original name.