Engineering guides

Replay SQL against historical inputs

KratosForge Editorial · 2026-11-18

Kratos and his wolf compare an earlier bronze shield on a shelf with its altered successor on the workbench.
Custom illustration · Keep the earlier state available when investigating a changed result.

A query that returned the right total yesterday can return a different total today without a single SQL edit. New rows, corrections and changed lookup values all move the inputs. When investigating a discrepancy, first decide which question you are asking: what the current data says, or what the data said at a particular cutoff. Save that cutoff with the query and the result you want to explain.

KratosForge’s merged time-travel implementation adds a practical way to ask the second question in local T-SQL. A SELECT ending in OPTION (FOR TIMESTAMP AS OF ...) reads its Delta tables at one UTC time, including tables reached through joins, CTEs and subqueries. This guide refers to main-branch commit 24581f1, merged in PR #2865. That merge does not establish Stable availability; check your installed build before using the hint. The Stable release checked on November 18 was last updated November 2.

The example below assumes dbo.sales is a Delta table with id and amount columns and retained history spanning the chosen cutoff. Replace the timestamp with a UTC time at which your table existed. The local syntax uses a literal in yyyy-MM-ddTHH:mm:ss format, optionally with up to three fractional digits. Keep this read in its own batch. The query changes no data.

SQL · Read a retained Delta snapshot in a build supporting local T-SQL time travel
SELECT id, amount
FROM dbo.sales
ORDER BY id
OPTION (FOR TIMESTAMP AS OF '2026-11-18T09:00:00');

Test the boundary with a small fixture before trusting an investigation. Create a Delta table with one known row, record a cutoff after that commit, then add a second row. The current query should return both rows; the historical query should return only the first. For a join, change a lookup row after the cutoff as well, so the test catches an input that accidentally stayed current. KratosForge’s pinned tests exercise historical reads, joins, CTEs, subqueries and unions; local verification reproduced the two-version read.

Watch the inputs that have no historical contract. In this implementation, a regular database table, file or view used as a historical table is refused because it has no Delta versions. A temporary table is read in its current state. If you join a historical fact table to a temporary lookup built from today’s data, you have deliberately mixed times. Build that lookup from the same historical inputs or record it as a separate fixture.

A timestamp alone also cannot preserve data that retention has removed. Keep the required transaction history and referenced data files available for the investigation, and test the actual retention behavior of the service you will query. Local Delta history does not prove that a remote warehouse retains the same cutoff. For a reproducible handoff, record the SQL, UTC cutoff, input identities, engine build and expected rows together. Then rerun that bundle after changing the current inputs: the historical answer should stay fixed.

← All publications

Search documentation

Start typing to search all 115 guides.

Search runs in your browser esc to close