Hello, I’m DocuDroid!
Submitting feedback
Thank you for rating our AI Search!
We would be grateful if you could share your thoughts so we can improve our AI Search for you and other readers.
GitHub

REFRESH MATERIALIZED VIEW

Replaces the contents of a materialized view.

Synopsis

REFRESH MATERIALIZED VIEW [ CONCURRENTLY ] <name> [ WITH [ NO ] DATA ]

Description

REFRESH MATERIALIZED VIEW completely replaces the contents of a materialized view. The old contents are discarded. To run this command, you must be the owner of the materialized view. With the default, WITH DATA, the materialized view query is run to provide the new data, and the materialized view is left in a scannable state. If WITH NO DATA is specified, no new data is generated and the materialized view is left in an unscannable state. A query returns an error if the query attempts to access the materialized view.

Parameters

Parameter Description

CONCURRENTLY

Refresh the materialized view without locking out concurrent selects on the materialized view. Without this option, a refresh that affects a lot of rows will tend to use fewer resources and complete more quickly, but could block other connections that are trying to read from the materialized view. This option may be faster in cases where a small number of rows are affected.

This option is only allowed if there is at least one UNIQUE index on the materialized view which uses only column names and includes all rows; that is, it must not be an expression index or include a WHERE clause.

This option cannot be used when the materialized view is not already populated, and it cannot be used with the WITH NO DATA clause.

Even with this option, only one REFRESH at a time may run against any one materialized view

name

The name (optionally schema-qualified) of the materialized view to refresh

Notes

While the default index for future CLUSTER operations is retained, REFRESH MATERIALIZED VIEW does not order the generated rows based on this property. If you want the data to be ordered upon generation, you must use an ORDER BY clause in the materialized view query. However, if a materialized view query contains an ORDER BY clause, the data is not guaranteed to be ordered if SELECT is performed on the materialized view.

Examples

This command replaces the contents of the order_summary materialized view using the query from the materialized view’s definition, and leaves it in a scannable state:

REFRESH MATERIALIZED VIEW order_summary;

This command frees storage associated with the annual_statistics_basis materialized view and leaves it in an unscannable state:

REFRESH MATERIALIZED VIEW annual_statistics_basis WITH NO DATA;

Compatibility

REFRESH MATERIALIZED VIEW is a Greengage DB extension of the SQL standard.

See also