相当于`information_schema`中的`pg_rules`

时间:2011-05-22 14:26:36

标签: postgresql rules

我知道,information_schema是SQL标准,RULES是Postgresql扩展。

是否有办法使用information_schema列出所有可用规则?

2 个答案:

答案 0 :(得分:3)

不,根据documentation

  

信息架构视图没有,   但是,包含有关的信息   PostgreSQL特有的功能;至   查询您需要查询的内容   系统目录或其他   PostgreSQL特定的视图。

答案 1 :(得分:2)

请尝试

SELECT
  n.nspname                   AS view_schema,
  c.relname                   AS view_name,
  r.rulename                  AS rule_name,
  pg_get_ruledef(r.oid, true) AS compiled_definition,
  d.description               AS full_description,
  CASE ev_type::integer
      WHEN 2 THEN 'update'
      WHEN 3 THEN 'insert'
      WHEN 4 THEN 'delete'
  END AS rule_event

FROM
  pg_rewrite AS r
  LEFT JOIN pg_class AS c ON c.oid = r.ev_class
  LEFT JOIN pg_namespace AS n ON n.oid = c.relnamespace
  LEFT JOIN pg_description AS d ON r.oid = d.objoid
WHERE TRUE
AND n.nspname != 'pg_catalog'
AND r.rulename <> '_RETURN' AND relkind = 'v'
ORDER BY r.rulename