Temporal and Versioned Rows
Valid-time and as-of queries.
What Are Temporal Tables?
Temporal tables let you track how data changes over time. Instead of overwriting a row when something changes, a temporal table keeps every version of that row, each tagged with the time period it was valid.
There are two key concepts: valid time (when the fact was true in the real world) and transaction time (when the database recorded the fact). Combining both gives you a fully bi-temporal table.
Valid Time vs. Transaction Time
Valid time represents when a fact is true in the real world — for example, an employee's salary from 2020-01-01 to 2022-06-30. Transaction time is when the database row was inserted or expired. Together they answer two questions: What was true? and When did we know it?
Most practical use cases start with valid-time tracking, which you can implement manually using valid_from and valid_to columns.
All lessons in this course
- Why Keep History
- Append-Only Event Tables
- Temporal and Versioned Rows
- Rebuilding State from Events