Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check a materialized view exists?

How do I check if a materialized view exists?

I have created one and checked in information_schema.tables and information_schema.viewsbut I cannot see it.

Where should I be looking?

like image 512
Guerrilla Avatar asked Nov 05 '19 23:11

Guerrilla


People also ask

How do you find materialized view on a table?

You can use the view DBA_DEPENDENCIES to view any dependencies for an object compiled into the database. Querying that view with the name of your materialized view should list all of the tables as well as any other dependencies the materialized view relies on.

Where is the materialized view stored?

A materialized view can be stored in the same database as its base tables or in a different database. Materialized views are often used to improve performance, especially when storing data locally that is sourced from tables or views using a database link.

How can you tell if a snowflake is materialized?

The command to find out whether a view is secure. For non-materialized views, check the IS_SECURE column in the output of the SHOW VIEWS command. For materialized views, check the IS_SECURE column in the output of the SHOW MATERIALIZED VIEWS command.


1 Answers

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)
like image 147
klin Avatar answered Sep 24 '22 21:09

klin