Prerequisites
Before creating a materialized view, you should have:- Basic familiarity with NQL syntax
- A dataset to query (your own or one you have access to)
- Understanding of what materialized views are and when to use them
Basic syntax
A materialized view is created with theCREATE MATERIALIZED VIEW statement:
Creating your first materialized view
Let’s create a simple materialized view that aggregates user counts by region.Step 1: Write and test your query
Start by writing the query you want to materialize. Run it to verify it returns the expected results:Step 2: Wrap it in CREATE MATERIALIZED VIEW
Once your query works, add theCREATE MATERIALIZED VIEW wrapper:
Step 3: Execute the statement
Run the statement to create the view. The query executes immediately and stores the results.Step 4: Query the materialized view
Once created, query it like any other table:Adding metadata options
You can configure how the view behaves using metadata options. The most common are:Setting a refresh schedule
To keep your view updated automatically:@hourly, @daily, @weekly, @monthly, and custom CRON expressions.
Adding a display name and description
Make your view easier to find in the UI:Partitioning for performance
For time-series data, partition by date to improve query performance:Refreshing materialized views
Views refresh according to their schedule. You can also trigger manual refreshes via the API when you need immediate updates.Scheduled refresh
Use theREFRESH_SCHEDULE option to set automatic refresh intervals:
| Schedule | When it runs |
|---|---|
@hourly | Every hour |
@daily | Once per day |
@weekly | Once per week |
@monthly | Once per month |
| CRON expression | Custom schedule |
Custom CRON schedules
For more control, use a CRON expression:Incremental refresh
For large datasets, NQL can refresh incrementally by processing only changed data. This happens automatically when the query pattern supports it. To learn more, see Incremental View Maintenance.Editing the refresh schedule and compute pool from the UI
You can change a materialized view’s refresh cadence and the compute pool that runs its scheduled refreshes without rewriting the view. From the dataset’s Overview screen, click the pencil icon next to the Refresh Schedule row:- Refresh schedule — pick a preset (
@hourly,@daily,@weekly,@monthly) or enter a custom CRON expression. - Compute pool — select which compute pool runs the scheduled refresh. The dropdown lists only active, company-owned pools on the dataset’s data plane, matching the pools you can pick in the Context Selector.
Write modes
Control how refreshes update the view data:Overwrite mode (default)
Each refresh replaces the entire view with fresh results:Append mode
Each refresh adds new data to the existing view:Example: Complete materialized view
Here’s a complete example combining multiple options:- Refreshes daily with fresh data
- Stores 160 days of female user demographics
- Partitions by day for efficient date-range queries
- Computes extended statistics for query optimization
- Retains all data indefinitely
Related content
Materialized Views
Understand when and why to use materialized views
Materialized View Syntax
Complete reference for all available options
Incremental View Maintenance
How NQL optimizes refreshes for large datasets
Query Optimization
Techniques for writing faster, more efficient queries

