> ## Documentation Index
> Fetch the complete documentation index at: https://docs.lancedb.com/llms.txt
> Use this file to discover all available pages before exploring further.

# SQL reference

> SQL statements, expressions and data types supported by LanceDB Enterprise.

LanceDB Enterprise supports SQL through an Arrow Flight SQL endpoint. This
reference covers statement syntax, data types and expressions. To set up a
client and run your first query, see [SQL](https://docs.lancedb.com/basics/sql.md).

## The dialect

LanceDB uses [Apache DataFusion](https://datafusion.apache.org) for SQL planning
and execution. These pages describe LanceDB's supported statements and
extensions. DataFusion's reference is useful for expression syntax, but does
not establish that every DataFusion statement or feature is exposed by
LanceDB.

## Connecting

Use Python's `execute_query` or a Flight SQL client after configuring the
[Enterprise connection](https://docs.lancedb.com/basics/sql.md#sql-is-remote). TypeScript applications
use a Flight SQL client for SQL queries.

```python Python icon="python" theme={"theme":{"light":"vitesse-light","dark":"catppuccin-mocha"}}
reader = db.execute_query("SELECT id, text FROM my_docs LIMIT 10")
for batch in reader:
    print(batch)
```

SQL results arrive as Arrow record batches. Iterating over the reader avoids
collecting the entire result in application memory. See
[Read and manage results](https://docs.lancedb.com/basics/sql.md#results) for more.

## 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 a merge insert. See
[What SQL cannot do](#cannot).

## Reference

### DDL, by object

| | |
| - | - |
| [Database](https://docs.lancedb.com/sql/ddl/database.md) | `CREATE`, `DESCRIBE`, `SHOW`, `ATTACH`, `DROP DATABASE` |
| [Namespace](https://docs.lancedb.com/sql/ddl/namespace.md) | `CREATE`, `ALTER`, `DESCRIBE`, `SHOW`, `DROP SCHEMA`/`NAMESPACE` |
| [Table](https://docs.lancedb.com/sql/ddl/table.md) | `CREATE`, `DESCRIBE`, `ALTER`, `CLONE`, `DROP TABLE` |
| [View](https://docs.lancedb.com/sql/ddl/view.md) | `CREATE VIEW`, `DROP VIEW` |
| [Materialized view](https://docs.lancedb.com/sql/ddl/materialized-view.md) | `CREATE MATERIALIZED VIEW`, `SHOW MATERIALIZED VIEWS` |
| [Secret](https://docs.lancedb.com/sql/ddl/secret.md) | `CREATE`, `ALTER`, `DESCRIBE`, `SHOW`, `DROP SECRET` |
| [Storage Integration](https://docs.lancedb.com/sql/ddl/storage-integration.md) | `CREATE`, `DESCRIBE`, `SHOW`, `DROP STORAGE INTEGRATION` |
| [Index](https://docs.lancedb.com/sql/ddl/index.md) | `CREATE INDEX`, `DROP INDEX` |
| [Function](https://docs.lancedb.com/sql/ddl/function.md) | `CREATE FUNCTION`, `SHOW FUNCTIONS`, `DROP FUNCTION` |
| [Job](https://docs.lancedb.com/sql/ddl/job.md) | `SHOW JOBS`, `SHOW JOB EVENTS`, `DESCRIBE JOB`, `SHOW ERRORS`, `PAUSE`/`RESUME`/`CANCEL JOB` |

### DML

| | |
| - | - |
| [Insert](https://docs.lancedb.com/sql/dml/insert.md) | `INSERT INTO`, including `INSERT ... SELECT` |
| [Update](https://docs.lancedb.com/sql/dml/update.md) | `UPDATE ... SET` |
| [Delete](https://docs.lancedb.com/sql/dml/delete.md) | `DELETE FROM` |
| [Copy](https://docs.lancedb.com/sql/dml/copy.md) | `COPY` (refused by recent deployment versions) |
| [Refresh column](https://docs.lancedb.com/sql/dml/refresh-column.md) | filling a computed column |
| [Refresh materialized view](https://docs.lancedb.com/sql/dml/refresh-materialized-view.md) | bringing a view's stored result up to date |

### DQL

| | |
| - | - |
| [Data types](https://docs.lancedb.com/sql/data-types.md) | how Lance columns appear to SQL, and pseudo-columns |
| [Select](https://docs.lancedb.com/sql/dql/select.md) | projection, filtering, ordering, set operations, CTEs |
| [Subqueries](https://docs.lancedb.com/sql/dql/subqueries.md) | scalar, `IN`, `EXISTS`, correlated, derived tables |
| [Joins](https://docs.lancedb.com/sql/dql/join.md) | inner, outer, cross, and namespace-qualified paths |
| [Aggregation](https://docs.lancedb.com/sql/dql/aggregation.md) | `GROUP BY`, `HAVING`, the aggregate set |
| [Window functions](https://docs.lancedb.com/sql/dql/window.md) | `OVER`, framing, ranking and offset functions |
| [Sampling](https://docs.lancedb.com/sql/dql/sampling.md) | `TABLESAMPLE`, by rows or by fragments |
| [Changes](https://docs.lancedb.com/sql/dql/changes.md) | `CHANGES`: rows appended since an earlier version |
| [Full-Text Search](https://docs.lancedb.com/sql/dql/fts.md) | the `fts()` table function, and its query forms |
| [Operators](https://docs.lancedb.com/sql/dql/operators.md) | comparison, logical, arithmetic, literals, precedence |
| [Functions](https://docs.lancedb.com/sql/dql/functions.md) | where to find each kind, and table functions |
| [Scalar functions](https://docs.lancedb.com/sql/dql/scalar-functions.md) | the per-row catalogue, and what Lance accelerates |
| [Explain](https://docs.lancedb.com/sql/dql/explain.md) | `EXPLAIN`, `EXPLAIN ANALYZE`, `EXPLAIN VERBOSE` |

## SQL limitations and alternatives

| | |
| - | - |
| Vector search | See [SQL vector search](https://docs.lancedb.com/basics/sql.md#no-vector-sql) for supported query forms and server-version requirements. The [SDK query builder](https://docs.lancedb.com/search/vector-search.md) also supports vector search. |
| Merge insert | no SQL form: it needs a source relation and a per-match policy |
| `information_schema` | not enabled, so `SHOW TABLES` and `SHOW COLUMNS` fail |
| `COPY` | refused by recent deployment versions (see [Copy](https://docs.lancedb.com/sql/dml/copy.md)) |
| `PREPARE` / `EXECUTE` | preparation is a [protocol feature](https://docs.lancedb.com/basics/sql.md#prepared-statements), not a statement |
| Run on a local database | no engine to plan the statement |

See [Limits](https://docs.lancedb.com/basics/limits.md#sql) for the bounds these pages enforce.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.