PostgreSQL 9.3:统计视图中包含的所有表

PostgreSQL 9.3: Count all tables contained in view

我想计算 view.

中包含的 tables 的数量

在SQL服务器中我是这样做的:

Declare v_tables int

SELECT  v_Tables = Count(*)
      FROM INFORMATION_SCHEMA.VIEW_TABLE_USAGE
      WHERE View_Name = View1;

PostgreSQL 9.3 怎么样?

CREATE OR REPLACE FUNCTION count_tables(p_viewname text) RETURNS integer AS $BODY$
  SELECT count(*) FROM information_schema.view_table_usage
  WHERE view_name = p_viewname;
$BODY$ LANGUAGE sql STABLE STRICT;