CREATE_MATERIALIZED_VIEW(7pg14)
π CREATE MATERIALIZED VIEW π
okay bestie, you found the CREATE_MATERIALIZED_VIEW(7pg14) page from the PostgreSQL 14.24 Documentation β and it's literally the manual page for defining a new materialized view. grab a strawberry π, we're doing this.
πΈ NAME πΈ
CREATE_MATERIALIZED_VIEW β define a new materialized view. periodt. π
β¨ SYNOPSIS β¨
CREATE MATERIALIZED VIEW [ IF NOT EXISTS ] table_name
[ (column_name [, ...] ) ]
[ USING method ]
[ WITH ( storage_parameter [= value] [, ... ] ) ]
[ TABLESPACE tablespace_name ]
AS query
[ WITH [ NO ] DATA ]
π DESCRIPTION π
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.
It's 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 β the way it remembers is iconic. A materialized view has many of the same properties as a table, but there is no support for temporary materialized views. not me checking for temp support... there is none.
CREATE MATERIALIZED VIEW requires CREATE privilege on the schema used for the materialized view. so yes, permissions check first, bestie π
π PARAMETERS π
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. iykyk, "if not exists" is not a promise that the existing thing is your vibe.table_nameβ the name (optionally schema-qualified) of the materialized view to be created. name it, bestie.column_nameβ 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.USING methodβ 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 typeTABLE. See Chapter 61 for more information. If this option is not specified, the default table access method is chosen for the new materialized view. Seedefault_table_access_methodfor more information.WITH ( storage_parameter [= value] [, ... ] )β this clause specifies optional storage parameters for the new materialized view; see Storage Parameters in theCREATE TABLE(CREATE_TABLE(7)) documentation for more information. All parameters supported forCREATE TABLEare also supported forCREATE MATERIALIZED VIEW. SeeCREATE TABLE(CREATE_TABLE(7)) for more information.TABLESPACE tablespace_nameβ thetablespace_nameis the name of the tablespace in which the new materialized view is to be created. If not specified,default_tablespaceis consulted.queryβ aSELECT,TABLE, orVALUEScommand. This query will run within a security-restricted operation; in particular, calls to functions that themselves create temporary tables will fail. heads up: this is a real caveat, not a drill.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 untilREFRESH MATERIALIZED VIEWis used. so if you skip the data, it's lowkey unqueryable until you refresh. facts.
π¦ COMPATIBILITY π¦
CREATE MATERIALIZED VIEW is a PostgreSQL extension. slay, it's ours π
π SEE ALSO π
ALTER MATERIALIZED VIEW(ALTER_MATERIALIZED_VIEW(7))CREATE TABLE AS(CREATE_TABLE_AS(7))CREATE VIEW(CREATE_VIEW(7))DROP MATERIALIZED VIEW(DROP_MATERIALIZED_VIEW(7))REFRESH MATERIALIZED VIEW(REFRESH_MATERIALIZED_VIEW(7))
okay that's the whole page, bestie β from the PostgreSQL 14.24 Documentation, dated 2026. now go define that materialized view and serve looks β¨ππ
π¦ where this page comes from
- opensuse-leap 16.0: postgresql14 14.24-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql14 14.24-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql14 14.24-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql14 14.24-160000.1.1 Β· PostgreSQL
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms