adam78
adam78

Reputation: 10068

Postgres SQL dropping table drops all dependent views?

In postgres when I drop a table it is dropping all views that depend upon it. Is there a way to persist the views so that they dont get dropped

Note: the table will be regenerated on daily basis with new data.

Upvotes: 1

Views: 3985

Answers (2)

Dave Sharpe
Dave Sharpe

Reputation: 21

Try TRUNCATE TABLE / CREATE TABLE IF NOT EXISTS instead of DROP.

Upvotes: 0

Vüsal
Vüsal

Reputation: 2706

From PostgreSQL documentation

DROP TABLE always removes any indexes, rules, triggers, and constraints that exist for the target table. However, to drop a table that is referenced by a view or a foreign-key constraint of another table, CASCADE must be specified. (CASCADE will remove a dependent view entirely, but in the foreign-key case it will only remove the foreign-key constraint, not the other table entirely.)

Upvotes: 2

Related Questions