CREATE VIEW | Materialize Documentation

Create view

To create a view:

CREATE [TEMP|TEMPORARY] VIEW [IF NOT EXISTS] <view_name>[(<col_ident>, ...)] AS
<select_stmt>;
Syntax element Description
TEMP / TEMPORARY

Optional. Mark the view as temporary. Temporary views are:

  • Created in the mz_temp schema.
  • Not visible to other connections.
  • Automatically dropped at the end of the SQL session
IF NOT EXISTS Optional. If specified, do not generate an error if a view with the same name already exists. If not specified, an error is generated if a view with the same name already exists.
<view_name> A name for the view.
(<col_ident>, ...) Optional if the SELECT statement return columns with unique names; else, is required if the SELECT statement returns multiple columns with the same identifier. If specified, renames the SELECT statement’s columns to the list of identifiers. Both must be the same length.
<select_stmt> The SELECT statement that defines the view.

Create or replace view

To create, or if a view exists with the same name, replace it with the view defined in this statement:

NOTE: You cannot replace views that other views depend on, nor can you replace a non-view object with a view.

CREATE OR REPLACE VIEW <view_name> [(<col_ident>, ...)] AS <select_stmt>;
Syntax element Description
<view_name> A name for the view.
(<col_ident>, ...) Optional if the SELECT statement return columns with unique names; else, is required if the SELECT statement returns multiple columns with the same identifier. If specified, renames the SELECT statement’s columns to the list of identifiers. Both must be the same length.
<select_stmt> The SELECT statement that defines the view.