VERSION AS OF (Time Travel)
The VERSION AS OF clause reads a catalog-backed table as of a specific snapshot id,
rather than a timestamp. VERSION AS OF PREVIOUS reads the snapshot immediately before the
current one, without you having to look up its id or commit time first.
Syntax
SELECT ...
FROM <table_name> VERSION AS OF <snapshot_id>
WHERE ...;
SELECT ...
FROM <table_name> VERSION AS OF PREVIOUS
WHERE ...;Parameters
<table_name>— the catalog-backed table to query as of the given snapshot.<snapshot_id>— a non-negative whole number identifying a snapshot, as reported bySHOW SNAPSHOTS FOR.0is reserved and is refused if you type it literally — usePREVIOUSinstead.PREVIOUS— the snapshot that is the parent of the current one. Resolved from the catalog at query time; you never need to know its id or timestamp.
Examples
Query a Specific Snapshot
SELECT * FROM my_workspace.sales.orders VERSION AS OF 1755000000000;Query the Version Before the Current One
SELECT * FROM my_workspace.sales.orders VERSION AS OF PREVIOUS;Find a Snapshot Id, Then Read It
SHOW SNAPSHOTS FOR my_workspace.sales.orders;
SELECT * FROM my_workspace.sales.orders VERSION AS OF 1755000000000;Notes
- Requires a catalog-backed table with a commit log — the same requirement as
TIMESTAMP AS OF; a plain filesystem/Parquet connection has no snapshots to travel through. VERSION AS OF 0is always refused, whether or not0happens to be a real snapshot id — it is reserved soPREVIOUShas an unambiguous internal form to resolve.PREVIOUShas no n-back form (there is noPREVIOUS 2); it always means exactly one snapshot back from current.PREVIOUSfails if the current snapshot has no parent (the table's first snapshot) or if the parent has since been reclaimed — see Snapshot Reclamation. Both are query errors, not empty results.- Resolving
PREVIOUSonly ever touches the current snapshot and the one before it — it does not read the table's full commit history, unlikeSHOW SNAPSHOTS FOR.
See Also
- SELECT
- TIMESTAMP AS OF — the timestamp-based form of time travel.
- SHOW SNAPSHOTS FOR — lists the snapshot ids a table has.
- Time Travel Queries — advanced topic covering reclamation, temporal self-joins, and partitioning requirements.