]> begriffs open source - ai-pg/blob - full-docs/txt/sql-creatematerializedview.txt
Convert HTML docs to more streamlined TXT
[ai-pg] / full-docs / txt / sql-creatematerializedview.txt
1
2 CREATE MATERIALIZED VIEW
3
4    CREATE MATERIALIZED VIEW — define a new materialized view
5
6 Synopsis
7
8 CREATE MATERIALIZED VIEW [ IF NOT EXISTS ] table_name
9     [ (column_name [, ...] ) ]
10     [ USING method ]
11     [ WITH ( storage_parameter [= value] [, ... ] ) ]
12     [ TABLESPACE tablespace_name ]
13     AS query
14     [ WITH [ NO ] DATA ]
15
16 Description
17
18    CREATE MATERIALIZED VIEW defines a materialized view of a query. The
19    query is executed and used to populate the view at the time the command
20    is issued (unless WITH NO DATA is used) and may be refreshed later
21    using REFRESH MATERIALIZED VIEW.
22
23    CREATE MATERIALIZED VIEW is similar to CREATE TABLE AS, except that it
24    also remembers the query used to initialize the view, so that it can be
25    refreshed later upon demand. A materialized view has many of the same
26    properties as a table, but there is no support for temporary
27    materialized views.
28
29    CREATE MATERIALIZED VIEW requires CREATE privilege on the schema used
30    for the materialized view.
31
32 Parameters
33
34    IF NOT EXISTS
35           Do not throw an error if a materialized view with the same name
36           already exists. A notice is issued in this case. Note that there
37           is no guarantee that the existing materialized view is anything
38           like the one that would have been created.
39
40    table_name
41           The name (optionally schema-qualified) of the materialized view
42           to be created. The name must be distinct from the name of any
43           other relation (table, sequence, index, view, materialized view,
44           or foreign table) in the same schema.
45
46    column_name
47           The name of a column in the new materialized view. If column
48           names are not provided, they are taken from the output column
49           names of the query.
50
51    USING method
52           This optional clause specifies the table access method to use to
53           store the contents for the new materialized view; the method
54           needs be an access method of type TABLE. See Chapter 62 for more
55           information. If this option is not specified, the default table
56           access method is chosen for the new materialized view. See
57           default_table_access_method for more information.
58
59    WITH ( storage_parameter [= value] [, ... ] )
60           This clause specifies optional storage parameters for the new
61           materialized view; see Storage Parameters in the CREATE TABLE
62           documentation for more information. All parameters supported for
63           CREATE TABLE are also supported for CREATE MATERIALIZED VIEW.
64           See CREATE TABLE for more information.
65
66    TABLESPACE tablespace_name
67           The tablespace_name is the name of the tablespace in which the
68           new materialized view is to be created. If not specified,
69           default_tablespace is consulted.
70
71    query
72           A SELECT, TABLE, or VALUES command. This query will run within a
73           security-restricted operation; in particular, calls to functions
74           that themselves create temporary tables will fail. Also, while
75           the query is running, the search_path is temporarily changed to
76           pg_catalog, pg_temp.
77
78    WITH [ NO ] DATA
79           This clause specifies whether or not the materialized view
80           should be populated at creation time. If not, the materialized
81           view will be flagged as unscannable and cannot be queried until
82           REFRESH MATERIALIZED VIEW is used.
83
84 Compatibility
85
86    CREATE MATERIALIZED VIEW is a PostgreSQL extension.
87
88 See Also
89
90    ALTER MATERIALIZED VIEW, CREATE TABLE AS, CREATE VIEW, DROP
91    MATERIALIZED VIEW, REFRESH MATERIALIZED VIEW