如何查找具有依赖于给定表的规则的所有视图和表?
我需要这个,以便找到哪些视图和表格,我必须检查是否要更改/删除给定的表。
答案 0 :(得分:1)
获取引用给定表格TABLENAME的视图或表格:
SELECT cl_r.relname AS ref_table
FROM pg_rewrite AS r
JOIN pg_class AS cl_r ON r.ev_class=cl_r.oid
JOIN pg_depend AS d ON r.oid=d.objid
JOIN pg_class AS cl_d ON d.refobjid=cl_d.oid
WHERE cl_d.relkind IN ('r','v') AND cl_d.relname='TABLENAME'
GROUP BY cl_r.relname
ORDER BY cl_r.relname;
我是通过颠倒以下答案来做到的:https://stackoverflow.com/a/4337615