# man > CREATE_MATERIALIZED_VIEW(7)

---
type: CommandReference
command: CREATE MATERIALIZED VIEW
mode: man
section: 7
source: man-pages
---

## Quick Reference

- `CREATE MATERIALIZED VIEW view_name AS query;` — create and populate a materialized view
- `CREATE MATERIALIZED VIEW view_name AS query WITH NO DATA;` — create empty, unscannable view (refresh later)
- `CREATE MATERIALIZED VIEW IF NOT EXISTS view_name AS query;` — create only if not exists
- `CREATE MATERIALIZED VIEW view_name (col1, col2) AS query;` — specify column names
- `CREATE MATERIALIZED VIEW view_name WITH (fillfactor = 70) AS query;` — set storage parameters
- `CREATE MATERIALIZED VIEW view_name TABLESPACE fast_space AS query;` — define tablespace
- `CREATE MATERIALIZED VIEW view_name USING heap AS query;` — use a specific table access method

## Name

define a new materialized view

## Synopsis

shell
CREATE MATERIALIZED VIEW [ IF NOT EXISTS ] table_name
    [ ( column_name [, ...] ) ]
    [ USING method ]
    [ WITH ( storage_parameter [= value] [, ... ] ) ]
    [ TABLESPACE tablespace_name ]
    AS query
    [ WITH [ NO ] DATA ]
## Options

- `IF NOT EXISTS` — do not error if a materialized view with the same name already exists; issue a notice instead
- `table_name` — name (optionally schema-qualified) of the materialized view to create
- `column_name` — name of a column in the new materialized view; if omitted, taken from query output column names
- `USING method` — table access method to store the contents (must be of type TABLE); defaults to `default_table_access_method`
- `WITH ( storage_parameter [= value] [, ...] )` — optional storage parameters (same as `CREATE TABLE`); see [Storage Parameters](https://www.postgresql.org/docs/14/sql-createtable.html#SQL-CREATETABLE-STORAGE-PARAMETERS)
- `TABLESPACE tablespace_name` — tablespace in which to create the materialized view; defaults to `default_tablespace`
- `query` — a `SELECT`, `TABLE`, or `VALUES` command; runs within a security-restricted operation (calls creating temporary tables will fail)
- `WITH [ NO ] DATA` — if `WITH NO DATA`, the view is created unscannable (must be refreshed before querying); if omitted, populated immediately

## See Also

- [ALTER MATERIALIZED VIEW](https://www.chedong.com/phpMan.php/man/VIEW/7/markdown)
- [CREATE TABLE AS](https://www.chedong.com/phpMan.php/man/AS/7/markdown)
- [CREATE VIEW](https://www.chedong.com/phpMan.php/man/VIEW/7/markdown)
- [DROP MATERIALIZED VIEW](https://www.chedong.com/phpMan.php/man/VIEW/7/markdown)
- [REFRESH MATERIALIZED VIEW](https://www.chedong.com/phpMan.php/man/VIEW/7/markdown)