Dropping a column in PostgreSQL is safe only after you know what goes with it, because a plain ALTER TABLE ... DROP COLUMN refuses for some dependents and drops others without a word. It stops for views, generated columns, row-level security policies and other tables’ foreign keys. It silently takes every index, unique constraint, CHECK and statistics object on its own table that uses the column, including indexes you think of as belonging to a different column.

We ran every statement below on PostgreSQL 18.3 in a throwaway container, against a customers table that has collected the usual history around one old column, legacy_code:

CREATE TABLE customers (
  id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
  email text NOT NULL,
  region text NOT NULL DEFAULT 'eu',
  legacy_code text,
  legacy_code_upper text GENERATED ALWAYS AS (upper(legacy_code)) STORED,
  CONSTRAINT customers_legacy_code_key UNIQUE (legacy_code),
  CONSTRAINT customers_region_legacy_code_key UNIQUE (region, legacy_code),
  CONSTRAINT customers_legacy_code_check CHECK (legacy_code IS NULL OR region <> 'test')
);
CREATE INDEX customers_legacy_code_idx ON customers (legacy_code);
CREATE INDEX customers_email_legacy_idx ON customers (email) WHERE legacy_code IS NOT NULL;
CREATE STATISTICS customers_region_code_stats ON region, legacy_code FROM customers;
CREATE TABLE orders (
  id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
  customer_code text REFERENCES customers (legacy_code)
);
CREATE VIEW customer_codes AS SELECT id, legacy_code FROM customers;
CREATE MATERIALIZED VIEW customer_code_counts AS
  SELECT legacy_code, count(*) FROM customers GROUP BY legacy_code;
ALTER TABLE customers ENABLE ROW LEVEL SECURITY;
CREATE POLICY customers_with_code ON customers USING (legacy_code IS NOT NULL);
CREATE FUNCTION customers_touch() RETURNS trigger LANGUAGE plpgsql AS $$
BEGIN NEW.legacy_code := trim(NEW.legacy_code); RETURN NEW; END $$;
CREATE TRIGGER customers_touch BEFORE INSERT OR UPDATE ON customers
  FOR EACH ROW EXECUTE FUNCTION customers_touch();
INSERT INTO customers (email, legacy_code) VALUES ('[email protected]', 'A1');

Is it safe to drop a column in Postgres?

It is safe when nothing outside the table’s own keys depends on the column and you have accepted losing every index, constraint and statistics object that uses it, because PostgreSQL reports the first group and not the second.

ALTER TABLE customers DROP COLUMN legacy_code; failed with cannot drop column legacy_code of table customers because other objects depend on it, and the detail named five objects:

ObjectWhat a plain DROP COLUMN does
Generated column legacy_code_upperRefuses
Foreign key orders_customer_code_fkey on ordersRefuses
View customer_codesRefuses
Materialized view customer_code_countsRefuses
Policy customers_with_codeRefuses
Unique constraints customers_legacy_code_key and customers_region_legacy_code_keyDrops them, no notice
CHECK customers_legacy_code_checkDrops it, no notice
Indexes customers_legacy_code_idx and customers_email_legacy_idxDrops them, no notice
Statistics customers_region_code_statsDrops it, no notice
Trigger function customers_touchNothing; it fails on the next insert

The error is the helpful half. It tells you where to look, and nothing has changed yet.

What does DROP COLUMN drop without a warning?

It drops every index and table constraint on the same table that involves the column, as the PostgreSQL ALTER TABLE documentation states: “Indexes and table constraints involving the column will be automatically dropped as well.”

To see it with nothing blocking, we built an accounts table with UNIQUE (tenant_id, handle), CHECK (handle IS NULL OR tenant_id > 0) and CREATE INDEX accounts_email_handle_idx ON accounts (email) WHERE handle IS NOT NULL, then ran ALTER TABLE accounts DROP COLUMN handle;. PostgreSQL answered ALTER TABLE. Afterwards pg_constraint held only the primary key and the NOT NULL constraints, and pg_indexes held only accounts_pkey.

Two of those losses are easy to miss in review. The partial index is an index on email; it went because its WHERE named handle, so any query that used it to find accounts by email now reads the table. And the multi-column CHECK disappears whole, so the rule about tenant_id it carried goes too. Statistics follow a narrower rule from the same page: a multivariate statistics object is removed when the drop would leave it with data for only one column, which is what happened to customers_region_code_stats.

What does DROP COLUMN CASCADE remove?

CASCADE removes the five blockers as well, and reports them only in a NOTICE, which a deploy log rarely puts in front of anyone.

ALTER TABLE customers DROP COLUMN legacy_code CASCADE; printed drop cascades to 5 other objects: the generated column, the foreign key on orders, both views and the policy. The foreign key belongs to another table, so orders.customer_code now holds codes that point at nothing, with no constraint left to say so.

The policy is the dangerous one. Row-level security stayed on for customers, and with no policy left the row security documentation applies its default: “If no policy exists for the table, a default-deny policy is used, meaning that no rows are visible or can be modified.” An application role with SELECT on the table counted 1 row before the drop and 0 after it. The owner still saw the row, so a check run as the migration’s own user would not notice.

The trigger was not in either list. PostgreSQL does not track what a PL/pgSQL body reads, so the drop succeeded and the next INSERT failed with record "new" has no field "legacy_code".

Does MySQL or SQL Server drop the same objects?

No: what PostgreSQL drops silently from the table’s own keys, MySQL and MariaDB partly keep or refuse, and SQL Server and SQLite refuse outright.

We ran one table per case on MySQL 8.4.11, MariaDB 11.4.13, SQL Server 2022 and SQLite 3.54.0:

Object that uses the dropped columnPostgreSQL 18.3MySQL 8.4MariaDB 11.4SQL Server 2022SQLite 3.54
Index on that column onlyDroppedDroppedDroppedRefusedRefused
Index on several columnsDroppedKept on the othersKept on the othersRefusedRefused
UNIQUE on several columnsDroppedKept on the othersRefusedRefusedRefused
CHECK over several columnsDroppedRefusedRefusedRefusedRefused
The table’s own foreign key columnDroppedRefusedRefusedRefusedRefused
Another table’s foreign key into itRefusedRefusedRefusedRefusedRefused, by the column’s own UNIQUE

MySQL’s row is the surprising one. Dropping x from UNIQUE (r, x) left UNIQUE KEY (r), a stricter rule than before, and on a table holding (1, 1) and (1, 2) the drop failed with Duplicate entry '1' for key 'd.d_rx_key'. SQL Server refuses every case with Msg 5074: The object 'd_rx_key' is dependent on column 'x', so a migration there has to drop each index and constraint first.

How do you find what a column drop will take?

Ask the catalogue for every object tied to the column before you write the migration, then decide about each one.

SELECT DISTINCT pg_describe_object(d.classid, d.objid, d.objsubid) AS dependent
FROM pg_depend d
JOIN pg_attribute a ON a.attrelid = d.refobjid AND a.attnum = d.refobjsubid
WHERE d.refobjid = 'customers'::regclass AND a.attname = 'legacy_code'
ORDER BY 1;

On our table it returned all eleven objects: three constraints on customers, the foreign key on orders, the generated column’s expression, both indexes, the policy, both views’ rewrite rules and the statistics object. It cannot return the trigger function, so search function bodies for the column name as well. Then write the drops you mean as statements of their own, and keep the ones you need, such as an index on email without the old WHERE, as new statements in the same migration.

How Schemity shows what a column drop takes with it

From the next release, Schemity Pro’s impact analysis lists the objects a column drop reaches, with what that database does to each: dropped with the column, kept on the other columns, or refusing the drop.

Schemity is database design software that reads your live database, shows the impact of every schema change before it runs, and keeps the diagram as a file in Git. Impact analysis is part of Schemity Pro. Paste this post’s ALTER TABLE customers DROP COLUMN legacy_code; into a diagram connected to the database, and its Dependent objects group lists eleven objects: the generated column, both views, the policy and the foreign key on orders as refusing the change, the two unique constraints, two indexes and the CHECK as dropped with the column, and the trigger as one that may fail when it next runs. The statistics object is the one it does not list yet. Delete the column on the canvas instead, and the migration Schemity writes drops the unique constraints and the index on legacy_code as statements of their own, where the change preview shows them. It also warns that the CHECK and the partial index on email still name legacy_code in their text, since the diagram keeps them and the next migration would try to create them again. It is the way to see the impact of every change before a NOTICE scrolls past in a deploy log.

Schemity's SQL migration drawer analysing ALTER TABLE customers DROP COLUMN legacy_code on PostgreSQL 18.3: Loses data names customers.legacy_code; Dependent objects says 11 objects depend on it and the database refuses the change, listing the materialized view, view, policy, generated column and the foreign key on orders as refusing, the trigger as one that fails the next time it runs, and the two unique keys, two indexes and the CHECK as dropped with the column without a warning; Spreads through the diagram reaches orders through orders_customer_code_fkey, 1 hop

Running this post’s table through Schemity is how that list came to be complete. The released app named the views, the generated column, the trigger and the reach into orders, and nothing else: no policy, no refusal from the foreign key on orders, and none of the silent drops. The free Migration Check CLI missed the generated column too, which the desktop app already reported. Both are fixed for the next release, with each database’s row of the table above, measured for this post, built into the analysis.

Should you drop the column at all?

Drop it once its dependents are dealt with one by one; when the list is long, stop writing to the column first and drop it in a later release.

That order also covers the code that still reads the column, which no catalogue lists. An agent-written migration is where an unread DROP COLUMN most often arrives, as reviewing what an AI agent’s migration does covers, and when the change is a type rather than a drop, changing a column type a view depends on shows the view errors you meet instead.

Frequently asked questions

Does dropping a column in PostgreSQL drop its indexes?

Yes, without a warning. PostgreSQL drops every index and table constraint that involves the column, including a multi-column unique constraint, a CHECK that reads it together with other columns, and a partial index on another column whose WHERE clause names it. Multivariate statistics go too when they would be left with one column.

Is DROP COLUMN CASCADE safe in PostgreSQL?

Only after you have read what it will remove. It also drops other tables' foreign keys into the column, views, materialized views, generated columns and row-level security policies, and lists them only in a NOTICE. A table with row-level security on and its last policy removed this way returns no rows to any role that is not the owner or exempt from RLS.

How do I find everything that depends on a column in PostgreSQL?

Query pg_depend for rows whose refobjid is the table and whose refobjsubid is the column's attnum, and pass each row to pg_describe_object. That lists indexes, constraints, statistics, views, policies and foreign keys from other tables. It cannot list a trigger function whose PL/pgSQL body uses the column, because function bodies are not tracked.