---
title: Lakehouses and SQL
slug: querying-data
summary: Lakehouses, schemas, and reading data with SQL through the Lake Query API.
---

# Lakehouses and SQL

Data lives in **lakehouses**: server-side data containers, one per logical dataset within a workspace. A lakehouse holds **schemas** (commonly `bronze` / `silver` / `gold`, or custom), and schemas hold **tables** and **files**.

Tables use **DuckLake**, DuckDB's native lakehouse format: the catalog lives in PostgreSQL and the data is Parquet in object storage. The catalog is the single source of truth; there is no repo `.lakehouse.yaml` to drift out of date.

## Discover

```
limilake lakehouse list
limilake lakehouse schema show my-lakehouse
limilake table list --lakehouse my-lakehouse
limilake lakehouse explain my-lakehouse
```

`explain` blends the live schema with this concept doc, the `kubectl explain` pattern.

`table list --lakehouse sales` accepts a canonical slug, qualified ref such as
`finance.sales`, or UUID, compared case-insensitively. It filters all readable discovery rows locally;
display names and partial matches are not selectors. If a slug exists in several
Workspaces, use its qualified ref or add `--workspace finance`. Like other
commands, discovery takes its Workspace from `--workspace`, then
`LIMILAKE_WORKSPACE`, then the linked checkout; outside a checkout, or with
`--all-workspaces`, it lists every discoverable table.
No matching rows is a successful empty result; table output names the filters; an incomplete or failed discovery returns an error.

## Read

Ad-hoc SQL runs through the HTTP Lake Query API (read-only, bounded). No local
data engine is required:

```
limilake query "SELECT customer, total FROM gold.sales ORDER BY total DESC LIMIT 20" \
  --lakehouse my-lakehouse

limilake table read gold.sales --lakehouse my-lakehouse --limit 50
```

Attach more than one lakehouse with repeated `--lakehouse` flags; reference each by its catalog alias in the SQL.

With `-o json` or `-o yaml`, both commands return positional `columns` and
`rows`, so repeated column names, nulls and exact numbers survive, with
`row_count`, `max_rows` and `limit_reached`.

## Search Indexes

A **Search Index** makes the text of a table searchable by words and by
meaning. Declare it once on a table; the platform builds it and keeps it up to
date as rows change. Search Index must be turned on for your tenant; until it
is, these commands exit 7 with `search_index_disabled`.

```
limilake search-index declare note_search --lakehouse crm --table crm.notes \
  --key note_id --text body --filter owner --date written_at --language english
limilake search-index list --lakehouse crm
limilake search-index show note_search --lakehouse crm
```

`--key` names the columns that identify a row, `--text` the text to search,
`--filter` columns a search can filter on, `--context` columns placed before
every passage, and `--date` one date or timestamp column for recency. Repeat a
flag for several columns. `--from-file PATH` takes the whole declaration as the
API's JSON body instead. Declaring the same thing again changes nothing; a
change that affects the build requests a rebuild (reordering `--filter`
columns does not), and the output says whether one was requested. `rebuild`
requests one by hand, and `delete` removes the index after confirmation (or
`--yes`). Declaring, rebuilding and deleting need `editor` access.

There is no separate search command: search in SQL with `search_index(...)`,
which returns one row per hit with the key columns, `_score` and the best
passage `_passage`, and join it to the table:

```
limilake query "SELECT n.subject, s._score, s._passage
  FROM search_index('note_search', 'renewal terms', k := 5) s
  JOIN crm.notes n USING (note_id)" --lakehouse crm
```

A refused search names its reason: `search_index_disabled` (exit 7) means
Search Index is not turned on for your tenant, `search_index_not_found` (exit
4) that no index of that name is built on the query's Lakehouses yet, and
`search_index_forbidden` (exit 5) that you may not read the indexed table or
every column the index stores.

## Download files

`--output-file` names the destination; `-o` and `--output` always select the
output format, wherever they appear:

```bash
limilake file download analytics 11111111-1111-4111-8111-111111111111 --output-file report.csv
limilake -o json file download analytics 11111111-1111-4111-8111-111111111111 --output-file report.csv
```

With `--output-file`, JSON and YAML report `schema_version:1`,
`action:file.download` and a `result` containing `file_id`, `output_file`, and
`size_bytes` after a complete transfer; table output prints one sentence.
Output paths expand `~`. The signed download URL is never printed. A failed
transfer leaves the existing destination intact. A destination named `-` is a
literal file, not stdout.

Without `--output-file`, the file's exact bytes go to stdout in every output
format. A failure in metadata mode writes the error document on stderr and on
JSON or YAML stdout; a raw stdout download keeps its errors on stderr.

## Provisioning

Lakehouses are platform objects, created via the API, never authored as files:

```
limilake lakehouse create analytics --workspace my-workspace
```

Creating a Lakehouse needs `editor` or `owner` access in its Workspace.

## Read-only by design

Lake queries are read-only and capped at `--max-rows`. The real enforcement is server-side (scoped storage credentials, short-lived database roles, and token scopes), so a query can only touch the data your mounts and grants allow. Any Workspace Access Level, `viewer` included, can query that Workspace's Lakehouses.
