Skip to content

Materialized View Operations ​

Operation: createMaterializedView ​

pgm.createMaterializedView( viewName, options, definition ) ​

IMPORTANT

Create a new materialized view - postgres docs

Arguments ​

NameTypeDescription
viewNamestringname of the new materialized view
optionsobjectCheck below for available options
definitionstringSQL of SELECT statement

Options ​

OptionTypeDescription
ifNotExistsbooleanadds IF NOT EXISTS clause
columnsstring or arrayuse if you want to name columns differently then inferred from definition
tablespacestringoptional
storageParametersobjectoptional key value pairs of Storage Parameters
databooleandefault undefined

Reverse Operation: dropMaterializedView ​

pgm.dropMaterializedView( viewName, options ) ​

IMPORTANT

Drop a materialized view - postgres docs

Arguments ​

NameTypeDescription
viewNamestringname of the view to delete
optionsobjectCheck below for available options

Options ​

OptionTypeDescription
ifExistsbooleandrops view only if it exists
cascadebooleandrops also dependent objects

Operation: alterMaterializedView ​

pgm.alterMaterializedView( viewName, options ) ​

IMPORTANT

Alter a materialized view - postgres docs

Arguments ​

NameTypeDescription
viewNamestringname of the view to alter
optionsobjectCheck below for available options

Options ​

OptionTypeDescription
clusterstringoptional index name for clustering
extensionstringoptional name of extension view is dependent on
storageParametersobjectoptional key value (null to reset) pairs of Storage Parameters

Operation: renameMaterializedView ​

pgm.renameMaterializedView( viewName, newViewName ) ​

IMPORTANT

Rename a materialized view - postgres docs

Arguments ​

NameTypeDescription
viewNameNameold name of the view
newViewNameNamenew name of the view

Renaming preserves the source schema, including during automatic reversal. See Renaming and schemas for destination-schema validation and supported PgLiteral identifiers.

To move a materialized view between schemas, use SQL explicitly, for example pgm.sql('ALTER MATERIALIZED VIEW "old_schema"."my_view" SET SCHEMA "new_schema"'). Provide the corresponding SQL in your down migration to reverse that move.

Operation: alterMaterializedViewColumn ​

pgm.renameMaterializedViewColumn( viewName, columnName, newColumnName ) ​

IMPORTANT

Rename a materialized view column - postgres docs

Arguments ​

NameTypeDescription
viewNamestringname of the view to alter
columnNamestringcurrent column name
newColumnNamestringnew column name

Operation: refreshMaterializedView ​

pgm.refreshMaterializedView( viewName, options ) ​

IMPORTANT

Refreshes a materialized view - postgres docs

Arguments ​

NameTypeDescription
viewNamestringName of the view to refresh
optionsobjectCheck below for available options

Options ​

OptionTypeDescription
concurrentlybooleandefault false
databooleandefault undefined