Define a new view.

Table of Contents


CREATE [ OR REPLACE ] VIEW view_ident AS query

Where query is a SELECT statement.


CREATE VIEW creates a named definition of a query. This name can be used in other statements instead of a table name to reference the saved query definition. A view is not materialized, instead the query is run every time a view is referenced in a query.

If OR REPLACE is used, an already existing view with the same name will be replaced.

If a schema name is given in the view_ident (some_schema.view_name), the view will be created in the specified schema.

Table and view names must be unique within a schema. A view cannot have the name of an already existing table.

Views are read-only. They cannot be used as a target relation in write operations.

See also


Privileges (Enterprise only)

Regular users need to have DDL permissions on the schema in which the view is being created. In addition the user creating the view requires DQL permissions on all relations that occur within the views query definition.