Answers:
从文档中:
select table_name from INFORMATION_SCHEMA.views;
如果您不希望获得系统视图,请尝试以下操作:
select table_name from INFORMATION_SCHEMA.views WHERE table_schema = ANY (current_schemas(false))
where table_schema='USERNAME'
到查询
public
架构。
您可以查询pg_catalog.pg_views
所需的信息:
select viewname from pg_catalog.pg_views;
精炼查询以获取架构名称(以防万一,如果您在不同的架构中有多个具有相同名称的视图),而忽略了这些系统视图:
select schemaname, viewname from pg_catalog.pg_views
where schemaname NOT IN ('pg_catalog', 'information_schema')
order by schemaname, viewname;
恕我直言,由于我对Phil的回答的评论中所述的原因,这种方法比查询INFORMATION_SCHEMA.views更好。
尝试:
SELECT n.nspname AS table_schema,
pg_catalog.pg_get_userbyid(c.relowner) AS table_owner,
c.relname AS table_name
FROM pg_catalog.pg_class c
LEFT JOIN pg_catalog.pg_namespace n ON (n.oid = c.relnamespace)
WHERE c.relkind = 'v'
;
如果需要更多详细信息,可以修改以下内容以适合您的需求:
SELECT n.nspname AS table_schema,
pg_catalog.pg_get_userbyid(c.relowner) AS table_owner,
c.relname AS table_name,
s.n_live_tup AS row_count,
count (a.attname) AS column_count,
pg_catalog.obj_description(c.oid, 'pg_class') AS comments,
CASE c.relkind
WHEN 'v'
THEN pg_catalog.pg_get_viewdef(c.oid, true)
ELSE null
END AS query
FROM pg_catalog.pg_class c
LEFT JOIN pg_catalog.pg_namespace n ON (n.oid = c.relnamespace)
LEFT JOIN pg_catalog.pg_attribute a ON (c.oid = a.attrelid AND a.attnum > 0 AND NOT a.attisdropped)
LEFT JOIN pg_catalog.pg_stat_all_tables s ON (c.oid = s.relid)
WHERE c.relkind = 'v'
GROUP BY n.nspname,
c.relowner,
c.relkind,
c.relname,
s.n_live_tup,
c.oid
ORDER BY n.nspname,
c.relname
;