小编Sea*_*ean的帖子

查询Postgres中物化视图的定义

我想知道如何在 Postgres 中查询物化视图的定义。作为参考,我希望做的与您可以为常规视图做的非常相似:

SELECT * FROM information_schema.views WHERE table_name = 'some_view';
Run Code Online (Sandbox Code Playgroud)

它为您提供以下列:

table_catalog
table_schema
table_name
view_definition
check_option
is_updatable
is_insertable_into
is_trigger_updatable
is_trigger_deletable
is_trigger_insertable_into
Run Code Online (Sandbox Code Playgroud)

这对于物化视图是可能的吗?

从我目前的研究来看,物化视图似乎被故意排除在 information_schema 之外,因为

information_schema 只能显示存在于 SQL 标准中的对象。

( http://www.postgresql.org/message-id/3794.1412980686@sss.pgh.pa.us )

由于它们似乎完全被排除在 information_schema 之外,我不知道如何解决这个问题,但我想做的是双重的:

  1. 查询特定的物化视图是否存在。(到目前为止,我发现这样做的唯一方法是尝试创建一个具有相同名称的 mat 视图,看看它是否会爆炸。)
  2. 然后查询物化视图的定义(类似于 上的view_definitioninformation_schema.views)。

postgresql materialized-view information-schema postgresql-9.4

27
推荐指数
2
解决办法
3万
查看次数