Skip to main content
Stored query results in are not automatically updated to reflect the latest state of the table(s) they query. The REFRESH updates the stored query results of a materialized view.
CockroachDB does not support materialized views that are refreshed on .

Required privileges

The user must have the on the materialized view. The of the materialized view and users with privileges implicitly have this privilege. To allow a non-owner to refresh a materialized view, run GRANT MAINTAIN ON <materialized-view> TO <role_or_user>;.

Synopsis

refresh_materialized_views syntax diagram

Parameters

ParameterDescription
opt_concurrentlyCONCURRENTLY (Default behavior) This keyword has no effect. It is present for PostgreSQL compatibility. All materialized views are refreshed concurrently with other jobs.
view_nameThe name of the materialized view to refresh.
opt_clear_dataWITH DATA (Default behavior) Refresh the stored query results.
WITH NO DATA Drop the query results of the materialized view from storage.
AS OF SYSTEM TIMEUse historical data when refreshing the view. This can reduce by leveraging . The timestamp must be within the . For more information, see .

Examples

The following example uses the , populated with some workload values. Suppose that you create a materialized view on the bank table:
Now suppose that you update the balance values of the bank table:
The changes can be seen in the table with a simple SELECT statement against the table:
Recall that materialized views do not automatically update their stored results. Selecting from overdrawn_accounts returns stored results, which are outdated:
To update the materialized view’s results, use a statement:

Refresh a materialized view with historical data using AS OF SYSTEM TIME

You can refresh a materialized view using historical data with the clause. This is useful for reducing by performing a when refreshing the view.
Historical data is available only within the .
Refresh a materialized view using to use the most recent data that is available for :
You can also specify an explicit timestamp:

See also