首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >删除支持表将删除物化视图。

删除支持表将删除物化视图。
EN

Stack Overflow用户
提问于 2022-04-04 21:20:15
回答 1查看 317关注 0票数 0

当删除物化视图的支持表时,物化视图也会被删除吗?我理解在没有支持表的情况下,物化视图是无效的,但是删除物化视图似乎有点不寻常。

物化视图如下所示

代码语言:javascript
复制
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;

请注意,在发出删除备份表的命令之前,物化视图将使用数据刷新。

EN

回答 1

Stack Overflow用户

发布于 2022-04-04 22:22:02

感谢postgres-松弛通道上的@Raptélan,他为我提供了带有delete table参数的cascade文档。根据文档,预期文档摘录的行为如下:

代码语言:javascript
复制
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参数。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71743843

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档