Complete reference for CREATE MATERIALIZED VIEW statement
The CREATE MATERIALIZED VIEW statement creates a stored dataset from a query result. Unlike regular queries that execute each time, materialized views persist their results for faster access.
Controls whether additional statistics are computed for the dataset.Syntax:
EXTENDED_STATS = 'all'EXTENDED_STATS = 'none'
Values:
Value
Description
all
Compute extended statistics including cardinality estimates, value distributions, and null counts
none
Skip extended statistics (faster refresh, less metadata)
Extended statistics help the query optimizer but increase refresh time. Use all for frequently queried views and none for large views where refresh speed is critical.
Partitioning improves query performance when filtering on the partitioned field. Choose a partition scheme that matches your most common query patterns.
Defines upsert logic that matches incoming rows against existing data during refresh. Use MERGE ON to update existing records and insert new ones without creating duplicates.Syntax:
MERGE ON <condition>WHEN MATCHED THEN UPDATE SET <column> = source.<column>, ...WHEN NOT MATCHED THEN INSERT (<columns>) VALUES (<values>)
Auto-generated aliases:
Alias
Description
source
References columns from the incoming query result
target
References columns from the existing materialized view
Example:
MERGE ON target.user_id IS NOT DISTINCT FROM source.user_idWHEN MATCHED THEN UPDATE SET email = source.email, last_seen = source.last_seenWHEN NOT MATCHED THEN INSERT (user_id, email, last_seen)VALUES (source.user_id, source.email, source.last_seen)
MERGE ON is only valid within CREATE MATERIALIZED VIEW statements. It cannot be used as a standalone command.
Stores female user demographics from the last 160 days
Partitions data by day for efficient time-based queries
Retains all historical data indefinitely
Computes full statistics for query optimization
If you need a lightweight query abstraction that re-evaluates at query time instead of storing results, consider using a view dataset instead. View datasets are created through the SDK or API with the create_as_view option rather than through NQL syntax.