CREATE MATERIALIZED VIEW
Turso Extension: Materialized views are a Turso-specific feature not available in SQLite. This feature is experimental and must be enabled before use.
Syntax
Parameters
| Parameter | Description |
|---|---|
IF NOT EXISTS | Prevents an error if a materialized view with the same name already exists. The statement is a no-op when the view is present. |
view-name | A unique name for the materialized view within the database. |
select-statement | The SELECT query that defines the materialized view’s contents. |
How Incremental View Maintenance Works
When you modify data in a table that underlies a materialized view, Turso incrementally updates the materialized view within the same transaction. There is no manualREFRESH step. The materialized view is always consistent with the base tables.
- Changes to the materialized view are committed or rolled back together with the changes to the base tables.
- Aggregations like
COUNT,SUM, andAVGare maintained efficiently — Turso does not recompute the entire result set on each change.
Current Limitations
- Not all SQL functions are supported in materialized view definitions.
- A materialized view cannot reference another view or materialized view.
- The
TEMPORARYmodifier is not supported for materialized views.
Examples
Precomputed Aggregations
Automatic Updates
Filtered Summary
See Also
- CREATE VIEW for standard (non-materialized) views
- DROP VIEW for removing materialized views
- SELECT for the query syntax used in view definitions