--- title: "Materialized view" sidebarTitle: "Materialized View" description: "Create, open, list and drop a table whose contents are defined by a query." icon: table keywords: ["materialized view", "create_materialized_view", "catalog", "ddl"] availability: embedded: unavailable enterprise: available --- A materialized view is a table whose contents are defined by a query over another table. The query is recorded in the view's schema, and a refresh brings its stored rows up to date with the source. The result is an ordinary table: queryable, indexable, searchable, and present in `table_names()`. Nothing about reading it is special. This page covers creating and managing one. Keeping it current is [Refresh a materialized view](/feature-engineering/refresh-materialized-view). In SQL, see [`REFRESH MATERIALIZED VIEW`](/sql/dml/refresh-materialized-view) and [`SHOW MATERIALIZED VIEWS`](/sql/ddl/materialized-view#show). ## Create a materialized view {#create} ```python Python icon="python" view = db.create_materialized_view( "frames_captioned", source="frames", select=["frame_id", "video_id", "ts", "caption"], where="selected = true", ) ``` ```typescript TypeScript icon="square-js" const view = await db.createMaterializedView("frames_captioned", "frames", { select: ["frame_id", "video_id", "ts", "caption"], where: "selected = true", }); ``` `source` names the table the view reads — here, a `frames` table with a `caption` column, filtered to the frames selected for captioning. See [Create a materialized view](/feature-engineering/materialized-views#create) for the full walkthrough. `select`, `where` and `limit` define the query. ## Open, list and drop views {#manage} | | Python | TypeScript | SQL | | --- | --- | --- | --- | | create | `create_materialized_view` | `createMaterializedView` | `CREATE MATERIALIZED VIEW` | | open | `open_materialized_view` | `openMaterializedView` | -- | | list | `list_materialized_views` | `listMaterializedViews` | `SHOW MATERIALIZED VIEWS` | | refresh | `refresh` | `refresh` | `REFRESH MATERIALIZED VIEW` | | drop | `drop_table` | `dropTable` | `DROP TABLE` | Enterprise Creating, refreshing and dropping a materialized view each have an async, job-returning counterpart -- `create_materialized_view_async`, `view.refresh_async()`, `drop_materialized_view_async` -- the same pattern as [`refresh_column_async`](/feature-engineering/refresh-column#async): each returns a [job](/basics/jobs) you `wait()` on instead of blocking. The async counterpart of the example [above](#create): ```python Python icon="python" from datetime import timedelta job = db.create_materialized_view_async( "frames_captioned", source="frames", select=["frame_id", "video_id", "ts", "caption"], where="selected = true", ) view = job.wait(timeout=timedelta(minutes=15)) ``` `create_materialized_view_async` also accepts `auto_refresh_enabled` and `auto_refresh_interval_seconds`; see [Automatic refresh](/feature-engineering/refresh-materialized-view#auto-refresh). On a local database, `list_materialized_views` reads table schemas to find views. On Enterprise, it asks the server for the view listing, as `SHOW MATERIALIZED VIEWS` does. A view is dropped with `drop_table`, because a materialized view **is** a table. That also means dropping one removes stored rows, unlike dropping a [view](/management/view), which removes only a saved query. ## Read the view and its definition {#working} `view.table` is the underlying table, for querying, indexing, or search. `view.definition` contains the query's select list, predicate and limit. Both are properties; on an async view, the definition is read with `await view.definition()`. ## Enterprise compatibility {#deployment} Enterprise supports creating and refreshing materialized views on remote compute. Use the SDK version supported by your deployment, or the [SQL interface](/sql/ddl/materialized-view). ## Related guides {#next} How a refresh works, and what it writes. The non-materialized counterpart, defined in SQL.