> ## 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 time travel

> Read a table at a version, tag, timestamp, or branch and compare snapshots in a join.

Enterprise only

Place an `AT` selector after a table name in `FROM` or `JOIN` to read a snapshot
without creating a clone. Each table reference selects its own snapshot, so one
statement can compare versions of the same table.

## Select a snapshot

```sql theme={"theme":{"light":"vitesse-light","dark":"catppuccin-mocha"}}
SELECT * FROM items AT VERSION 42;
SELECT * FROM items AT TAG 'release-1';
SELECT * FROM items AT TIMESTAMP '2026-11-01T00:00:00Z';
SELECT * FROM items AT BRANCH 'dev';
```

| Selector | What it reads |
| - | - |
| `AT VERSION n` | The specified positive integer version on the main branch. |
| `AT TAG 'name'` | The version currently named by that tag on the main branch. |
| `AT TIMESTAMP 'timestamp'` | The latest retained main-branch version committed at or before the timestamp. |
| `AT BRANCH 'name'` | A snapshot of the named branch's latest version when the statement is planned. Use `'main'` for the main branch. |

Use literal values for selectors. Put an alias after the selector:

```sql theme={"theme":{"light":"vitesse-light","dark":"catppuccin-mocha"}}
SELECT snapshot.id
FROM items AT TAG 'release-1' AS snapshot;
```

The selected snapshot determines both rows and schema. A column removed in a
later version can still be selected from an older version that contains it.
A statement without an `AT` selector continues to read the current table.

Timestamp selectors accept RFC 3339 timestamps, dates such as `'2026-11-01'`,
and date-time strings such as `'2026-11-01 12:00:00'`. Values without a time
zone use UTC. A timestamp after the latest commit selects the latest version;
a timestamp before every retained commit fails planning.

Tags and branch heads are resolved while planning each statement. Later
statements can read different snapshots after a tag or branch moves. Each
reference keeps its selected snapshot for that execution.

## Compare versions or branches

Join snapshots using a stored key. This query finds IDs added between two
versions:

```sql theme={"theme":{"light":"vitesse-light","dark":"catppuccin-mocha"}}
SELECT newer.id
FROM items AT VERSION 43 AS newer
LEFT JOIN items AT VERSION 42 AS older ON newer.id = older.id
WHERE older.id IS NULL;
```

Selectors can also be mixed in a join:

```sql theme={"theme":{"light":"vitesse-light","dark":"catppuccin-mocha"}}
SELECT released.id
FROM items AT TAG 'release-1' AS released
JOIN items AT BRANCH 'dev' AS development
  ON released.id = development.id;
```

## Retention and supported tables

The selected version and its data must still be retained. A missing version,
tag, or branch fails planning; `AT` cannot recover versions removed by cleanup.
Coordinate version retention with the period your queries need to inspect.
Reading a snapshot requires the usual `SELECT` permission on its table.

Selectors are supported only on native Lance base tables. WAL-backed tables
are rejected because rows in the fresh tier do not have Lance table versions.
Selectors cannot be applied to view results, CTE results, table functions, or
write targets, and cannot appear in persistent view definitions. A CTE can
contain a selected base table:

```sql theme={"theme":{"light":"vitesse-light","dark":"catppuccin-mocha"}}
WITH snapshot AS (SELECT id FROM items AT VERSION 42)
SELECT * FROM snapshot;
```


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