This section is a brief introduction to database views and their management, including creating, modifying, and removing them from a database.
A view is a database object that can usually be accessed as a virtual table, but which comes from a stored query. A PostgreSQL view is a logical table that represents data of underlying table(s) via a
Views do not store data physically. What views enable is for the user to convert the following complex query…
…into this far simpler one.
- help simplify query complexity because you can query a view using a simple
- can have permissions assigned
- are a consistent layer, even if the underlying data changes
To create a view, use
Then, the following much simpler query can be run in lieu of the longer query above. As suggested by the syntax below, ‘customer_info’ can be thought of as a virtual table.
The following command allows users to rename views.
Following that command, the following can be run.
IF EXISTS, in the following query, is optional.