How do I check if a materialized view exists?
I have created one and checked in information_schema.tables
and information_schema.views
but I cannot see it.
Where should I be looking?
How do I check if a materialized view exists?
I have created one and checked in information_schema.tables
and information_schema.views
but I cannot see it.
Where should I be looking?
Use the system catalog pg_class
, e.g.:
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)
or the system view 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)