Materialized View Operations
Operation: createMaterializedView
pgm.createMaterializedView( viewName, options, definition )
IMPORTANT
Create a new materialized view - postgres docs
Arguments
| Name | Type | Description |
|---|---|---|
viewName | string | name of the new materialized view |
options | object | Check below for available options |
definition | string | SQL of SELECT statement |
Options
| Option | Type | Description |
|---|---|---|
ifNotExists | boolean | adds IF NOT EXISTS clause |
columns | string or array | use if you want to name columns differently then inferred from definition |
tablespace | string | optional |
storageParameters | object | optional key value pairs of Storage Parameters |
data | boolean | default undefined |
Storage parameter names are quoted and folded to lowercase, without camel-case conversion. Dotted names specify a namespace and parameter, for example 'toast.autovacuum_enabled': false. Values may be booleans or finite numbers:
pgm.createMaterializedView(
'account_summary',
{ storageParameters: { fillfactor: 70, 'toast.autovacuum_enabled': false } },
'SELECT * FROM accounts'
);NaN, Infinity, and -Infinity throw a TypeError naming the option and value during SQL generation, before SQL for that operation is queued. Finite numbers, including negatives, zero, and decimals, are rendered unchanged; PostgreSQL still validates parameter-specific ranges and supported values.
Reverse Operation: dropMaterializedView
pgm.dropMaterializedView( viewName, options )
IMPORTANT
Drop a materialized view - postgres docs
Arguments
| Name | Type | Description |
|---|---|---|
viewName | string | name of the view to delete |
options | object | Check below for available options |
Options
| Option | Type | Description |
|---|---|---|
ifExists | boolean | drops view only if it exists |
cascade | boolean | drops also dependent objects |
Operation: alterMaterializedView
pgm.alterMaterializedView( viewName, options )
IMPORTANT
Alter a materialized view - postgres docs
Arguments
| Name | Type | Description |
|---|---|---|
viewName | string | name of the view to alter |
options | object | Check below for available options |
Options
| Option | Type | Description |
|---|---|---|
cluster | string | optional index name for clustering |
extension | string | optional name of extension view is dependent on |
storageParameters | object | optional key value (null to reset) pairs of Storage Parameters |
storageParameters uses the same name escaping and finite-number validation as createMaterializedView. Use null to reset a parameter, including namespaced parameters such as { 'toast.autovacuum_enabled': null }; other entries are applied with SET.
Operation: renameMaterializedView
pgm.renameMaterializedView( viewName, newViewName )
IMPORTANT
Rename a materialized view - postgres docs
Arguments
| Name | Type | Description |
|---|---|---|
viewName | Name | old name of the view |
newViewName | Name | new 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
| Name | Type | Description |
|---|---|---|
viewName | string | name of the view to alter |
columnName | string | current column name |
newColumnName | string | new column name |
Operation: refreshMaterializedView
pgm.refreshMaterializedView( viewName, options )
IMPORTANT
Refreshes a materialized view - postgres docs
Arguments
| Name | Type | Description |
|---|---|---|
viewName | string | Name of the view to refresh |
options | object | Check below for available options |
Options
| Option | Type | Description |
|---|---|---|
concurrently | boolean | default false |
data | boolean | default undefined |