Files
lancedb/docs/web/management/materialized-view.mdx
T
Jack Ye ddb318567a docs: complete SQL reference, enrich Functions drafts, rename OSS to Embedded (#4732)
## Summary

- Complete the SQL reference: `ATTACH DATABASE`, the `CHANGES` clause,
and
`dedupe()`/`duplicate_pairs()` (verified against current sophon source;
these were recently renamed from
`vector_dedup`/`vector_duplicate_pairs`).
  Fix the blob-column default-projection claim and add the previously
  undocumented `blob_descriptor()`.
- Enrich the gated Functions draft (still `.mintignore`'d, pre-release):
  chained Functions over blob outputs, GPU-produced blobs, Secrets,
  multi-input/output binding, `code=[module]` packaging.
- Upgrade the materialized-view and computed-column auto-refresh drafts
with
  precise, verified catch-up semantics, and add the missing `ALTER
  MATERIALIZED VIEW` / `CREATE ... WITH(...)` sections (also gated — the
  automatic-refresh scheduler is still dev/staging-only).
- Thread one running example (video frames → GPU extract/caption → dedup
→
auto-refreshing materialized view) through Functions, materialized
views,
and the LeRobotDataset integration guide instead of a separate tutorial.
- Rename "LanceDB OSS"/"OSS" to "LanceDB Embedded"/"Embedded" throughout
  (52 files); activate the existing availability-comparison mechanism on
  `basics/offerings.mdx` for a full feature-by-feature comparison table.
2026-10-29 10:16:03 -07:00

117 lines
4.3 KiB
Plaintext

---
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).
<Note>
In SQL, see [`REFRESH MATERIALIZED VIEW`](/sql/dml/refresh-materialized-view) and [`SHOW MATERIALIZED VIEWS`](/sql/ddl/materialized-view#show).
</Note>
## Create a materialized view {#create}
<CodeGroup>
```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",
});
```
</CodeGroup>
`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` |
<Badge color="red">Enterprise</Badge> 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):
<CodeGroup>
```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))
```
</CodeGroup>
`create_materialized_view_async` also accepts `auto_refresh_enabled` and
`auto_refresh_interval_seconds`; see
[Automatic refresh](/feature-engineering/refresh-materialized-view#auto-refresh).
<Note>
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.
</Note>
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}
<CardGroup cols={2}>
<Card title="Refresh a materialized view" icon="arrows-rotate" href="/feature-engineering/refresh-materialized-view">
How a refresh works, and what it writes.
</Card>
<Card title="Views" icon="eye" href="/management/view">
The non-materialized counterpart, defined in SQL.
</Card>
</CardGroup>