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.
Enterprise-only
LanceDB Enterprise comes with an SQL endpoint that can be used for analytical queries and data exploration. The SQL endpoint is designed to be compatible with the
Arrow FlightSQL protocol, which allows you to use any Arrow FlightSQL-compatible client to query your data.
Installing the client
There are Flight SQL clients available for most languages and tools. If you find that your
preferred language or tool is not listed here, please reach out to us and we can help you find a solution. The following examples demonstrate how to install the Python and TypeScript
clients.
# The `flightsql-dbapi` package provides a Python DB API 2 interface to the
# LanceDB SQL endpoint. You can use it to connect to the SQL endpoint and
# execute queries directly and get back results in pyarrow format.
pip install flightsql-dbapi
Usage
LanceDB uses the powerful DataFusion query engine to execute SQL queries. This means that
you can use a wide variety of SQL syntax and functions to query your data. For more detailed
information on the SQL syntax and functions supported by DataFusion, please refer to the
DataFusion documentation.
Setting Up the Client
Establish a connection to your LanceDB Enterprise SQL endpoint using your preferred FlightSQL client:
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"},
)
Executing a Query
Run SQL queries against your LanceDB tables. Different clients may handle the FlightSQL protocol differently:
def run_query(query: str):
"""Simple method to fully materialize query results"""
info = client.execute(query)
if len(info.endpoints) != 1:
raise Error("Expected exactly one endpoint")
ticket = info.endpoints[0].ticket
reader = client.do_get(ticket)
return reader.read_all()
result = run_query("SELECT * FROM flights WHERE origin = 'SFO'")
Processing Results
Handle the query results returned by your FlightSQL client: