Views
-
PostgreSQL view is a logical table that represents data of one or more underlying tables through a SELECT statement.
-
A view does not store data physically except for a materialized view.
-
A view can be very useful in some cases such as:
-
A view helps simplify the complexity of a query because you can query a view, which is based on a complex query, using a simple SELECT statement.
- Like a table, you can grant permission to users through a view that contains specific data that the users are authorized to see.
-
A view provides a consistent layer even the columns of underlying table changes.
-
Creating View in Postgresql:
CREATE VIEW view_name AS query;
- Altering View
ALTER VIEW customer_master RENAME TO customer_info;
- Dropping a view
DROP VIEW IF EXISTS customer_info;
Materialized View
-
PostgreSQL extends the view concept to the next level that allows views to store data physically. And these views are called materialized views.
-
Materialized views cache the result of a complex and expensive query and allow you to refresh this result periodically.
-
The materialized views are useful in many cases that require fast data access therefore they are often used in data warehouses and business intelligence applications.