最近学习使用postgresql,遇到一个难题,我知道postgresql如何判断一个表存在,select count(*) from pg_statio_user_tables where relname='你的表名';按照SQL的理解,pg_statio_user_tables就是管理表的系统表,如果是SQL的话,表和视图应该是一起管理的,但postgresql好像不是,但好像又没有pg_statio_user_views这个系统表。
请问各位高手,如何判断一个视图是否存在呢?
请问各位高手,如何判断一个视图是否存在呢?
The view pg_views provides access to useful information about each view in the database.
The view pg_views provides access to useful information about each view in the database. Table 44.58. pg_views ColumnsName Type References Description
schemaname name pg_namespace.nspname Name of schema containing view
viewname name pg_class.relname Name of view
viewowner name pg_authid.rolname Name of view's owner
definition text View definition (a reconstructed SELECT query)
select count(*) from pg_views where relname='viewname'
可判断viewname是否存在?
select * from pg_views where schemaname = 'public' and viewname = 'v_test';
查询总耗时: 18 ms.
检索到 1 行。
应该还可以在pg_class找出,只是没有那么直观