Menu

PostgreSQL DROP COLUMN: What It Refuses, and What It Drops Without a Warning
📰

PostgreSQL DROP COLUMN: What It Refuses, and What It Drops Without a Warning

DEV Community: mysql·Son Tran·9 days ago
#1rlPCPY1
#devtomysql#devto#dev#column#table
Long article (1806 words) — no AI summary yet.
Reading 0:00
15s threshold

Disclosure: I build Schemity , a desktop ERD tool - this post is from our blog and uses it for the examples.

TL;DR: A plain DROP COLUMN in PostgreSQL stops only for objects outside the table's own keys: views, other tables' foreign keys, generated columns and row-level security policies. Every index, unique constraint, CHECK and statistics object that uses the column is dropped with it, with no notice, including a partial index on a different column whose WHERE names it. CASCADE removes the blockers too, and a policy removed that way can leave the table showing zero rows to your application.

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.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.