【问题标题】:PostgreSQL: how to see which table RULEs existsPostgreSQL:如何查看存在哪些表规则
【发布时间】:2021-07-16 08:00:58
【问题描述】:

出于审计目的,我们在表上使用RULEs 而不是TRIGGER。

有没有办法查看存在哪些规则(information_schema 可能)?

另外,我可以查看规则的来源吗?可能类似于pg_proc。

【问题讨论】:

    标签: postgresql triggers rules


    【解决方案1】:

    这存储在pg_rewrite

    您可以使用这样的查询来为public 架构中的所有表制定规则:

    select r.rulename, 
           c.relname as rule_table,
           case r.ev_type  
             when '1' then 'SELECT' 
             when '2' then 'UPDATE' 
             when '3' then 'INSERT' 
             when '4' then 'DELETE' 
           end as rule_event, 
           pg_catalog.pg_get_ruledef(r.oid, true) as definition
    from pg_catalog.pg_rewrite r  
      join pg_catalog.pg_class c on r.ev_class = c.oid 
    where c.relnamespace = 'public'::regnamespace
      and r.rulename <> '_RETURN';
    

    r.rulename &lt;&gt; '_RETURN' 不包括为视图创建的规则。

    【讨论】:

      猜你喜欢
      • 2015-11-22
      • 1970-01-01
      • 2013-12-10
      • 1970-01-01
      • 1970-01-01
      • 2012-12-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多