检查物化视图是否存在?

Gue*_*lla 6 postgresql materialized-views

如何检查物化视图是否存在?

我创建了一个并签入information_schema.tablesinformation_schema.views但我看不到它。

我应该去哪里找?

kli*_*lin 6

使用系统目录pg_class,例如:

create materialized view my_view as select 1;

select relname, relkind
from pg_class
where relname = 'my_view'
and relkind = 'm';

 relname | relkind 
---------+---------
 my_view | m
(1 row)
Run Code Online (Sandbox Code Playgroud)

或系统视图pg_matviews

select *
from pg_matviews
where matviewname = 'my_view';  

 schemaname | matviewname | matviewowner | tablespace | hasindexes | ispopulated | definition 
------------+-------------+--------------+------------+------------+-------------+------------
 public     | my_view     | postgres     |            | f          | t           |  SELECT 1;
(1 row)
Run Code Online (Sandbox Code Playgroud)