patternsqlMajor
Replace a materialized view in Postgres
Viewed 0 times
materializedreplaceviewpostgres
Problem
I have a materialized view in
ERROR: cannot drop materialized view latest_charges because other objects depend on it
It also appears from the documentation that the REPLACE keyword isn't valid for a materialized view. Is there any shortcut aside from dropping all dependent objects and rebuilding each one?
Postgres 9.3 that I'd like to update with new columns. However, other materialized views also depend upon this view, and the error message indicates that dropping a view isn't possible when other objects depend on it. ERROR: cannot drop materialized view latest_charges because other objects depend on it
It also appears from the documentation that the REPLACE keyword isn't valid for a materialized view. Is there any shortcut aside from dropping all dependent objects and rebuilding each one?
Solution
As of PostgreSQL 9.4: Different to the documentation of CREATE VIEW, the documentation of CREATE MATERIALIZED VIEW does NOT mention the REPLACE keyword. There seems to be no shortcut aside from dropping all dependent objects and rebuilding each one.
When you do so, I can only recommend two small things:
When you do so, I can only recommend two small things:
- Use DROP MATERIALIZED VIEW blabla CASCADE to get a list of all dependent objects
- Do the drop and recreation of all dependent object in one transaction.
Context
StackExchange Database Administrators Q#56304, answer score: 35
Revisions (0)
No revisions yet.