A view is named query that provides another way to present data in the database tables. A view is defined based on one or more tables, which are known as base tables. When you create a view, you basically create a query and assign it a name, therefore a view is useful for wrapping a commonly used complex query.
Note that a normal view does not store any data except the materialized view. In PostgreSQL, you can create a special view called a materialized view that stores data physically and refreshes the data periodically from the base tables. The materialized views have many advantages in many scenarios such as faster access to data from a remote server, data caching, etc.
In this section, we will introduce you to the PostgreSQL views concept and show you how to manage views such as creating, modifying, and removing views from the database. In addition, we will illustrate how to create updatable views and give you a complete example of materialized views, which is a very powerful feature of PostgreSQL.
- Managing PostgreSQL views – introduces you to the views concept and show you how to create, modify, and remove PostgreSQL views.
- Creating PostgreSQL updatable views – gives you examples of creating updatable views that allow you to issue INSERT, UPDATE, and DELETE statement to update data in the base tables through the views.
- PostgreSQL materialized views – shows you the concept of materialized views and provides you with the steps of creating and refreshing data for a materialized view.
- Creating updatable views using the WITH CHECK OPTION clause – shows you how to use the
WITH CHECK OPTION
clause to check the view-defining condition when you make a change to the base table through the view. We also discuss the scope of check includingLOCAL
andCASCADED
. - Creating recursive views – introduces you to the recursive view and shows you an example of creating a recursive view in PostgreSQL.