最近学习使用postgresql,遇到一个难题,我知道postgresql如何判断一个表存在,select count(*) from pg_statio_user_tables where relname='你的表名';按照SQL的理解,pg_statio_user_tables就是管理表的系统表,如果是SQL的话,表和视图应该是一起管理的,但postgresql好像不是,但好像又没有pg_statio_user_views这个系统表。
请问各位高手,如何判断一个视图是否存在呢?

解决方案 »

  1.   

    The document said.
    The view pg_views provides access to useful information about each view in the database. 
      

  2.   

    44.58. pg_views
    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) 
      

  3.   

    楼上的意思是,用以下这句
    select count(*) from pg_views where relname='viewname'
    可判断viewname是否存在?
      

  4.   

    create view v_test as select version();查询成功但无结果,耗时: 615 毫秒(ms)。
    select * from pg_views where schemaname = 'public' and viewname = 'v_test';
    查询总耗时: 18 ms.
    检索到 1 行。
      

  5.   

    楼上说的是对的
    应该还可以在pg_class找出,只是没有那么直观