Skip to main content
You use the CREATE MATERIALIZED VIEW statement to create s. To learn more, see the how-to guides. The syntax is:
<select_query> is of the form:
The view defaults to WITH DATA. This means that when the view is created, it refreshes using all the current data in the underlying or . This occurs once when the view is created. If you want the view to be refreshed regularly, you can use a refresh policy. If you do not want the view to update when it is first created, use the WITH NO DATA parameter. For more information, see refresh_continuous_aggregate. s have some limitations of what types of queries they can support. For more information, see the s section. In v2.17.0 and greater (with 15+), you can dramatically decrease the amount of data written on a in the presence of a small number of changes, reduce the I/O cost of refreshing a , and generate fewer Write-Ahead Logs (WAL) by enabling the timescaledb.enable_merge_on_cagg_refresh GUC parameter. This enables refresh to use MERGE instead of deleting old materialized data and re-inserting. This parameter only works for finalized s that don’t have compression enabled. It is disabled by default. To enable this parameter for your session:
To enable it at the database level:
For more information about GUC parameters, see the configuration documentation. For more settings for s, see timescaledb_information.continuous_aggregates.

Samples

Create a daily view:
Add a thirty day on top of the same raw :
Add an hourly on top of the same raw :

Arguments

WITH clause options:

Returns

For standard CREATE MATERIALIZED VIEW return behavior, see the PostgreSQL CREATE MATERIALIZED VIEW documentation. For more information, see the real-time aggregates section.