当删除物化视图的支持表时,物化视图也会被删除吗?我理解在没有支持表的情况下,物化视图是无效的,但是删除物化视图似乎有点不寻常。
物化视图如下所示
create materialized view if not exists ea_master.geography_hierarchy
as
Select
parent.geography_id as parent_geography_id
,child.geography_id as child_geography_id
from ea_master.Geography parent
join ea_master.Polygon pParent on pParent.polygon_id = parent.polygon_id
join ea_master.Polygon pChild on ST_Contains(pParent.geometry, pChild.geometry)
join ea_master.Geography child on child.polygon_id = pChild.polygon_id
with no data;用于删除备份表的查询:DROP TABLE ea_master.geography CASCADE;
请注意,在发出删除备份表的命令之前,物化视图将使用数据刷新。
发布于 2022-04-04 22:22:02
感谢postgres-松弛通道上的@Raptélan,他为我提供了带有delete table参数的cascade文档。根据文档,预期文档摘录的行为如下:
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.)不幸的是,似乎需要级联参数来删除支持表,以确保视图与其一起被删除。每次使用级联选项删除备份表时,我都必须重新创建视图。
此外,我还将这个级联参数与外键合并为on delete cascade参数。
https://stackoverflow.com/questions/71743843
复制相似问题