Update a materialized view

Use the API to change materialized view properties.

Code sample

Python

Before trying this sample, follow the Python setup instructions in the BigQuery Quickstart Using Client Libraries. For more information, see the BigQuery Python API reference documentation.

import datetime
from google.cloud import bigquery

bigquery_client = bigquery.Client()

view_id = "my-project.my_dataset.my_materialized_view"
view = bigquery.Table(view_id)
view.mview_enable_refresh = True
view.mview_refresh_interval = datetime.timedelta(hours=1)

# Make an API request to update the materialized view.
view = bigquery_client.update_table(
    view,
    # Pass in a list of any fields you need to modify.
    ["mview_enable_refresh", "mview_refresh_interval"],
)
print(f"Updated {view.table_type}: {str(view.reference)}")

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser