mirror of
https://github.com/lancedb/lancedb.git
synced 2026-10-13 23:32:27 +00:00
Move the public website pages into `docs/web` beside the SDK, with
shared navigation and executable example sources in `docs/web-tests`.
The combined website is assembled by
[lancedb/docs#355](https://github.com/lancedb/docs/pull/355), with six
Enterprise replacements from
[lancedb/sophon#7681](https://github.com/lancedb/sophon/pull/7681).
This includes Function guidance, runnable Quickstarts, regenerated
snippets, production contact/demo fixes, the legacy SQL route, and the
LeRobot redirect. LeRobot remains attributed to Geneva; all 34 Geneva
pages remain in the docs repository until Function officially launches.
Materialized-view guidance follows the full rebuild refresh introduced
by #4373: local refresh writes the complete result, has no `full`
argument, supports `source_version`, and no longer requires stable row
IDs. Deployment SQL refresh options and stable-ID setup are qualified by
version/configuration. Function input guidance distinguishes ordinary
stored columns from computed inputs supported by newer deployments.
**Validation:** independently accepted local checks include 95 Python
tests (real Enterprise excluded), eight TypeScript tests, Rust
Quickstart, snippet parity, typos, deterministic assembly, Mint
validation and links/anchors/redirects. The combined baseline retains
all 181 production routes and 17 legacy redirects. Examples ran locally
against source-built Python SDK 0.40.0b13; existing GitHub workflows do
not run `docs/web-tests`. New main at `069b2f7d` is 0.41.0b0 and adds
computed Function inputs; that SDK was not exercised by the accepted
tests. Latest prose corrections receive focused site validation.
**Merge/rollout:** merge this and #7681 before #355's combined CI, which
reads producer `main`. This is migration infrastructure: section
overlays, source-owned skills and automatic versioned paired releases
remain follow-ups. The current manual publisher is transitional. Hosted
validation, a supported SDK/Enterprise release pair and a real
Enterprise walkthrough remain pending.
Production Mintlify watches `lancedb/docs:deploy-freeze`, directory
`docs`; preserve that source through review. The separate SDK GitHub
Pages reference workflow rebuilds on main merges.
**Updated-head CI (9a50f8db):**
[Typos](https://github.com/lancedb/lancedb/actions/runs/37654185443/job/112904990558),
[PR
title](https://github.com/lancedb/lancedb/actions/runs/37654179507/job/112904974595)
and
[Aikido](https://app.aikido.dev/featurebranch/scan/215386145?groupId=74229)
pass. Critical findings in the example lockfiles were patched: all Sharp
copies use 0.35.5, protobufjs 7.6.6, tar 7.5.22, quinn-proto 0.11.19,
zerovec 0.11.8 and zerovec-derive 0.11.6. The SDK's product dependencies
are unchanged. The revised lockfiles pass eight TypeScript examples,
HuggingFace decode/resize/crop/rescale/normalize plus AVIF roundtrip,
and Rust Quickstart. Aikido passing does not mean every advisory is
cleared; npm still reports 29 high and five moderate advisories in the
example dependency graph. No scanner bypass or suppression was added.
The Function prose correction passes combined/standalone Mint,
deterministic assembly, routes and assets. The revised 325-file site
checksum is
`175bec06864abb400dd292e667ba93448c0479b8359fd7bf6146afabf9040647`. This
PR remains open for independent review; further merges are on hold.
---------
Co-authored-by: Brendan Clement <brendan.clement@lancedb.com>
151 lines
5.7 KiB
Plaintext
151 lines
5.7 KiB
Plaintext
---
|
|
title: "SQL reference"
|
|
sidebarTitle: "Overview"
|
|
description: "The SQL surface: dialect, connecting a client, and a page per construct."
|
|
icon: table-list
|
|
keywords: ["sql", "datafusion", "flight sql", "reference", "dialect"]
|
|
---
|
|
|
|
<Badge color="red">Enterprise</Badge> SQL runs on a deployment. A local database
|
|
has no engine to plan a statement, so `execute_query` raises there -- see
|
|
[SQL](/basics/sql#sql-is-remote).
|
|
|
|
This is a reference rather than a guide: one page per construct, syntax first.
|
|
The guides elsewhere in these docs show the same operations from the SDKs.
|
|
|
|
## The dialect {#dialect}
|
|
|
|
LanceDB executes SQL with [Apache DataFusion](https://datafusion.apache.org),
|
|
currently **version 54**. The grammar, built-in functions and type system are
|
|
DataFusion's, so anything its reference documents for that version works here
|
|
unchanged and is not reproduced.
|
|
|
|
What these pages add is the part that is LanceDB's: how a query reaches the
|
|
engine, how Lance columns appear to it, and the statements a lakehouse needs
|
|
that DataFusion has no concept of.
|
|
|
|
## Connecting {#connecting}
|
|
|
|
SQL is served over an
|
|
[Arrow Flight SQL](https://arrow.apache.org/docs/format/FlightSql.html)
|
|
endpoint, so any Flight SQL client reaches it and results arrive as Arrow
|
|
record batches -- nothing is converted to pandas or Python objects unless you
|
|
ask.
|
|
|
|
From Python, the connection runs SQL directly, without a separate client:
|
|
|
|
```python
|
|
reader = db.execute_query("SELECT id, text FROM my_docs LIMIT 10")
|
|
table = reader.read_all()
|
|
```
|
|
|
|
`execute_query` hands back a reader as soon as the first batch is ready rather
|
|
than when the query finishes, so a large result set does not have to fit in
|
|
memory before you start reading it. See [Queries](/basics/query).
|
|
|
|
The TypeScript SDK has no SQL method; reach for a Flight SQL client instead --
|
|
and in Python, reach for one too when the caller is outside the SDK's own
|
|
process, such as a BI tool or a notebook in another language:
|
|
|
|
```bash
|
|
pip install flightsql-dbapi # Python DB API 2 interface
|
|
npm install --save @lancedb/flightsql-client
|
|
```
|
|
|
|
<CodeGroup>
|
|
```python Python icon="python"
|
|
from flightsql import FlightSQLClient
|
|
|
|
client = FlightSQLClient(
|
|
host="your-enterprise-endpoint",
|
|
port=10025,
|
|
insecure=True,
|
|
token="DATABASE_TOKEN",
|
|
metadata={"database": "your-project-slug"},
|
|
features={"metadata-reflection": "true"},
|
|
)
|
|
|
|
info = client.execute("SELECT * FROM flights WHERE origin = 'SFO'")
|
|
ticket = info.endpoints[0].ticket
|
|
result = client.do_get(ticket).read_all()
|
|
```
|
|
|
|
```typescript TypeScript icon="square-js"
|
|
import { Client } from "@lancedb/flightsql-client";
|
|
|
|
const client = await Client.connect({
|
|
host: "your-enterprise-endpoint:10025",
|
|
username: "lancedb",
|
|
password: "password",
|
|
});
|
|
|
|
const result = await client.query("SELECT * FROM flights WHERE origin = 'SFO'");
|
|
```
|
|
</CodeGroup>
|
|
|
|
## Usage {#usage}
|
|
|
|
The endpoint executes one statement per request and is meant for the queries
|
|
and DDL/DML pages below. Reach for the SDKs instead for table-management
|
|
operations that have no SQL form, such as building a vector index or a merge
|
|
insert -- see [What SQL cannot do](#cannot).
|
|
|
|
## Reference {#reference}
|
|
|
|
### DDL, by object {#ddl}
|
|
|
|
| | |
|
|
| --- | --- |
|
|
| [Namespace](/sql/ddl/namespace) | `CREATE SCHEMA`, `DROP SCHEMA` |
|
|
| [Table](/sql/ddl/table) | `CREATE`, `DESCRIBE`, `ALTER`, `CLONE`, `DROP TABLE` |
|
|
| [View](/sql/ddl/view) | `CREATE VIEW`, `DROP VIEW` |
|
|
| [Materialized view](/sql/ddl/materialized-view) | `CREATE MATERIALIZED VIEW`, `SHOW MATERIALIZED VIEWS` |
|
|
| [Index](/sql/ddl/index) | `CREATE INDEX`, `DROP INDEX` |
|
|
| [Function](/sql/ddl/function) | `CREATE FUNCTION`, `SHOW FUNCTIONS`, `DROP FUNCTION` |
|
|
| [Job](/sql/ddl/job) | `SHOW JOBS`, `SHOW ERRORS`, `PAUSE`/`RESUME`/`CANCEL JOB` |
|
|
|
|
### DML {#dml}
|
|
|
|
| | |
|
|
| --- | --- |
|
|
| [Insert](/sql/dml/insert) | `INSERT INTO`, including `INSERT ... SELECT` |
|
|
| [Update](/sql/dml/update) | `UPDATE ... SET` |
|
|
| [Delete](/sql/dml/delete) | `DELETE FROM` |
|
|
| [Copy](/sql/dml/copy) | `COPY INTO` / `COPY TO` |
|
|
| [Refresh](/sql/dml/refresh) | filling computed columns and materialized views |
|
|
|
|
### DQL {#dql}
|
|
|
|
| | |
|
|
| --- | --- |
|
|
| [Data types](/sql/data-types) | how Lance columns appear to SQL, and pseudo-columns |
|
|
| [Select](/sql/dql/select) | projection, filtering, ordering, set operations, CTEs |
|
|
| [Subqueries](/sql/dql/subqueries) | scalar, `IN`, `EXISTS`, correlated, derived tables |
|
|
| [Joins](/sql/dql/join) | inner, outer, cross, and namespace-qualified paths |
|
|
| [Aggregation](/sql/dql/aggregation) | `GROUP BY`, `HAVING`, the aggregate set |
|
|
| [Window functions](/sql/dql/window) | `OVER`, framing, ranking and offset functions |
|
|
| [Sampling](/sql/dql/sampling) | `TABLESAMPLE`, by rows or by fragments |
|
|
| [Full-Text Search](/sql/dql/fts) | the `fts()` table function, and its query forms |
|
|
| [Explain](/sql/dql/explain) | `EXPLAIN`, `EXPLAIN ANALYZE`, `EXPLAIN VERBOSE` |
|
|
|
|
### Expressions {#expressions}
|
|
|
|
| | |
|
|
| --- | --- |
|
|
| [Operators](/sql/operators) | comparison, logical, arithmetic, literals, precedence |
|
|
| [Functions](/sql/functions) | where to find each kind, and table functions |
|
|
| [Scalar functions](/sql/scalar-functions) | the per-row catalogue, and what Lance accelerates |
|
|
| [Prepared statements](/sql/prepared-statements) | planning once, executing many times |
|
|
|
|
## What SQL cannot do {#cannot}
|
|
|
|
| | |
|
|
| --- | --- |
|
|
| Vector search | no SQL form -- a query-builder operation |
|
|
| Merge insert | no SQL form -- needs a source relation and a per-match policy |
|
|
| `information_schema` | not enabled, so `SHOW TABLES` and `SHOW COLUMNS` fail |
|
|
| `PREPARE` / `EXECUTE` | preparation is a [protocol feature](/sql/prepared-statements), not a statement |
|
|
| Run on a local database | no engine to plan the statement |
|
|
|
|
See [Limits](/basics/limits#sql) for the bounds these pages enforce.
|