
Query a table at a specific timestamp (time travel)
Source:R/time_travel.R
get_ducklake_table_asof.RdRetrieves data from a DuckLake table as it existed at a specific point in time using DuckLake's AT (TIMESTAMP => ...) syntax.
Details
DuckLake supports time-travel queries, allowing you to query historical data
as it existed at a specific timestamp. This uses the syntax:
SELECT * FROM table AT (TIMESTAMP => 'timestamp')
This is useful for:
Auditing changes over time
Recovering accidentally deleted or modified data
Comparing data states across different time points
Regulatory compliance and data lineage documentation
The timestamp must be within the range of available snapshots for the table.
Use list_table_snapshots() to see available snapshot times.
Important: When querying at a snapshot's exact timestamp, you may need to add a small time buffer (e.g., +1 second) to ensure the snapshot is found. This is because the time-travel query looks for snapshots created at or before the specified timestamp.
Examples
if (FALSE) { # \dontrun{
# Query data as it existed yesterday
yesterday <- Sys.time() - (24 * 60 * 60)
get_ducklake_table_asof("my_table", yesterday) |>
filter(category == "A") |>
collect()
# Query data at a specific snapshot time
snapshots <- list_table_snapshots("my_table")
# Add 1 second to ensure the snapshot is found
get_ducklake_table_asof("my_table", snapshots$snapshot_time[2] + 1) |>
summarise(total = sum(amount))
} # }