The ALTER TABLE ... DROP COLUMN statement removes one or more columns from an existing table. PostgreSQL automatically removes any indexes and constraints that were defined on the dropped column. If other database objects such as views, triggers, or stored functions reference the column, you must either update those objects first or use the CASCADE option to drop them along with the column.
DROP COLUMN syntax
-- Drop a single column
ALTER TABLE table_name DROP COLUMN column_name;
-- Drop only if it exists (no error if missing)
ALTER TABLE table_name DROP COLUMN IF EXISTS column_name;
-- Drop and cascade to dependent objects
ALTER TABLE table_name DROP COLUMN column_name CASCADE;
-- Drop multiple columns at once
ALTER TABLE table_name
DROP COLUMN col1,
DROP COLUMN col2;
DROP COLUMN examples
Set up demo tables and a view:
CREATE TABLE publishers (
publisher_id SERIAL PRIMARY KEY,
name VARCHAR(255) NOT NULL
);
CREATE TABLE categories (
category_id SERIAL PRIMARY KEY,
name VARCHAR(255) NOT NULL
);
CREATE TABLE books (
book_id SERIAL PRIMARY KEY,
title VARCHAR(255) NOT NULL,
isbn VARCHAR(255) NOT NULL,
published_date DATE NOT NULL,
description VARCHAR,
category_id INT NOT NULL REFERENCES categories (category_id),
publisher_id INT NOT NULL REFERENCES publishers (publisher_id)
);
CREATE VIEW book_info AS
SELECT book_id, title, isbn, published_date, name
FROM books b
INNER JOIN publishers USING (publisher_id)
ORDER BY title;
Drop a column with a foreign key constraint:
ALTER TABLE books DROP COLUMN category_id;
This automatically removes the foreign key constraint on category_id.
Attempt to drop a column used by a view (fails without CASCADE):
ALTER TABLE books DROP COLUMN publisher_id;
-- ERROR: cannot drop table books column publisher_id because other objects depend on it
-- DETAIL: view book_info depends on table books column publisher_id
-- HINT: Use DROP ... CASCADE to drop the dependent objects too.
Drop with CASCADE to remove the dependent view as well:
ALTER TABLE books DROP COLUMN publisher_id CASCADE;
-- NOTICE: drop cascades to view book_info
Drop multiple columns simultaneously:
ALTER TABLE books
DROP COLUMN isbn,
DROP COLUMN description;
DROP COLUMN tips
- Dropping a column marks it as invisible but may not immediately reclaim disk space on large tables. Run
VACUUM FULLorCLUSTERto physically reclaim the space (both rewrite the table and require an exclusive lock). - Use
IF EXISTSin deployment scripts to make them idempotent — the statement becomes a no-op if the column was already dropped. - Be careful with
CASCADE— it drops all dependent views, rules, triggers, and functions. Review dependencies withd+ table_namein psql before proceeding. - Drop multiple columns in one
ALTER TABLEstatement to minimize locking: each statement acquires ACCESS EXCLUSIVE.
Reference: PostgreSQL documentation — ALTER TABLE.