【问题标题】:Listing tables USED BY materialized view in PostgreSQL?列出PostgreSQL中物化视图使用的表?
【发布时间】:2022-04-26 06:02:14
【问题描述】:

我用谷歌搜索过,都找不到答案。

如何在 PostgreSQL 中列出物化视图使用的表(不得使用 information_schema 视图)?

提前感谢您的帮助。

【问题讨论】:

标签: sql postgresql materialized-views


【解决方案1】:

参考这篇文章:How to get materialized views that refer to a table in postgresql

也在这里编写查询:

select distinct current_database()::information_schema.sql_identifier as view_catalog
              , nv.nspname::information_schema.sql_identifier as view_schema
              , v.relname::information_schema.sql_identifier as view_name
              , current_database()::information_schema.sql_identifier as table_catalog
              , nt.nspname::information_schema.sql_identifier as table_schema
              , t.relname::information_schema.sql_identifier as table_name
from pg_namespace nv
   , pg_class v
   , pg_depend dv
   , pg_depend dt
   , pg_class t
   , pg_namespace nt
where nv.oid = v.relnamespace and v.relkind = 'm'::"char" and v.oid = dv.refobjid and
    dv.refclassid = 'pg_class'::regclass::oid and dv.classid = 'pg_rewrite'::regclass::oid and
    dv.deptype = 'i'::"char" and dv.objid = dt.objid and dv.refobjid <> dt.refobjid and
      v.relname='<YOUR MATERIALIZED VIEW HERE>' and
    dt.classid = 'pg_rewrite'::regclass::oid and dt.refclassid = 'pg_class'::regclass::oid and dt.refobjid = t.oid and
    t.relnamespace = nt.oid and (t.relkind = any (array ['r'::"char", 'v'::"char", 'm'::"char", 'p'::"char"])) and
    pg_has_role(t.relowner, 'USAGE'::text);

【讨论】:

    猜你喜欢
    • 2016-12-08
    • 1970-01-01
    • 2015-09-16
    • 1970-01-01
    • 1970-01-01
    • 2022-08-09
    • 2018-01-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多