CREATE MATERIALIZED VIEW
CREATE MATERIALIZED VIEW — define a new materialized view
CREATE MATERIALIZED VIEW [ IF NOT EXISTS ]
column_name[, ...] ) ] [ USING
method] [ WITH (
value] [, ... ] ) ] [ TABLESPACE
query[ WITH [ NO ] DATA ]
CREATE MATERIALIZED VIEW defines a materialized view of a query. The query is executed and used to populate the view at the time the command is issued (unless
WITH NO DATA is used) and may be refreshed later using
REFRESH MATERIALIZED VIEW.
CREATE MATERIALIZED VIEW is similar to
CREATE TABLE AS, except that it also remembers the query used to initialize the view, so that it can be refreshed later upon demand. A materialized view has many of the same properties as a table, but there is no support for temporary materialized views.
IF NOT EXISTS
Do not throw an error if a materialized view with the same name already exists. A notice is issued in this case. Note that there is no guarantee that the existing materialized view is anything like the one that would have been created.
The name (optionally schema-qualified) of the materialized view to be created.
The name of a column in the new materialized view. If column names are not provided, they are taken from the output column names of the query.
This optional clause specifies the table access method to use to store the contents for the new materialized view; the method needs be an access method of type
TABLE. See Chapter 60 for more information. If this option is not specified, the default table access method is chosen for the new materialized view. See default_table_access_method for more information.
value] [, ... ] )
This clause specifies optional storage parameters for the new materialized view; see Storage Parameters for more information. All parameters supported for
CREATE TABLEare also supported for
CREATE MATERIALIZED VIEW. See CREATE TABLE for more information.
tablespace_nameis the name of the tablespace in which the new materialized view is to be created. If not specified, default_tablespace is consulted.
WITH [ NO ] DATA
This clause specifies whether or not the materialized view should be populated at creation time. If not, the materialized view will be flagged as unscannable and cannot be queried until
REFRESH MATERIALIZED VIEWis used.
CREATE MATERIALIZED VIEW is a PostgreSQL extension.