# Time Travel Query

> Reading a table as it was at an earlier time. Mistakes can be undone.

**Field:** Data Engineering  
**Category:** Storage & Warehousing  
**Also known as:** Time Travel, Table Versioning

## Think of it like

It is like undo in a drawing app. You can see the picture as it was an hour ago.

## Definition

Time travel lets you query a table as it was at an earlier time or version. Each change keeps the old data for a while instead of wiping it. A query names a version number or a timestamp. It is used to undo mistakes, check old reports and repeat old results. Old versions are kept only for a set number of days.

## Example

A bad job deletes half the orders table at 3pm. At 3:10pm, the team reads the 2pm version and puts it back.

## Example code

```sql
SELECT COUNT(*) FROM orders VERSION AS OF 12;
SELECT COUNT(*) FROM orders TIMESTAMP AS OF '2026-11-15';
```

Count the orders as they were at version 12, and at the start of a past day.

## Why it matters

Mistakes in data are common. Time travel turns a lost day into a ten-minute fix.

## Common mistake

Treating it as a backup. Old versions are cleaned out after a set time, and then they are gone.

## Three principles

- **Past versions.** Each change keeps the old one for a while.
- **Query by time.** Name a version or a timestamp.
- **Not forever.** Old versions expire after a set time.

## Related terms

- [Open Table Format](https://learn.benibix.com/term/data/open-table-format)
- [Delta Lake](https://learn.benibix.com/term/data/delta-lake)
- [Apache Iceberg](https://learn.benibix.com/term/data/apache-iceberg)
- [Snowflake](https://learn.benibix.com/term/data/snowflake)

---

Source: https://learn.benibix.com/term/data/time-travel
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-16
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
