Contents /
Previous /
Next
Views
Views are pseudo-tables, not physically materialized.
A view can represent a subset of a real table, selecting certain
columns or certain rows from an ordinary table. It can also
represent joined tables.
Because views are assigned separate
permissions, you can use them to restrict table access so that users
see only specific rows or columns of a table.
Although views are not real tables, they appear as
ordinary tables to SELECT.
Views should be read only:
the system should not allow an insert, update, or delete on a view.
CREATE VIEW will define a view of a table:
CREATE VIEW view [ ( column_name_list ) ] AS SELECT query
column_name_list is an optional list of names to be used for columns
of the view. If given, these names override the column names that
would be deduced from the SQL query.
Example:
CREATE VIEW bio_stud AS
SELECT name, diploma
FROM stud WHERE diploma = 'bio' ;
SELECT * FROM bio_stud ;
name | diploma
------+---------
fred | bio
tom | bio
lisa | bio
A view can be removed with DROP VIEW, example:
DROP VIEW bio_stud;