tl;dr:有什么方法可以在 postgres 中定义物化 View 而不立即用数据填充它,而只是在刷新时?
背景:我有一个 flyway 可重复脚本,它创建了一个对大量数据进行大量聚合的物化 View 。是否有可能创建 View 定义,以便将其映射到 hibernate 实体而不会出现任何错误,但它可以为空并在刷新时填充数据。每天晚上会刷新一次,不想影响应用启动时间。
堆栈:postgres 11,spring boot 2,hibernate 5
最佳答案
使用 WITH NO DATA
选项:
create materialized view bla_bla
as
select *
from foo_foo
WITH NO DATA;
引自 the manual :
WITH [ NO ] DATA
This clause specifies whether or not the materialized view should be populated at creation time. If not, the materialized view will be flagged as unscannable and cannot be queried until REFRESH MATERIALIZED VIEW is used
然而,这意味着在刷新之前访问该物化 View 的任何尝试都将导致错误,而不仅仅是一个空结果。
关于postgresql - 推迟物化 View 的创建,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58009632/