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?
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.
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.
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.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With