3) Updating the past
In part 2, we queried the historical timeline, to understand what changes were made.
In this part, we will understand how to insert historical data into XTDB.
How does this work with an immutable database!? Let’s find out together.
Let’s pretend the day today is 2024-01-01
, and we insert a product:
Let’s query the day after this insert:
Now, let’s query against the past, in 2023
We should NOT see any data, because the product was inserted into the database on 2024-01-01
:
Inserting historical data
But let’s say, we want to insert some historical data into our database, all the way back in 2022.
This could be an import of historical product prices from another system into our XTDB golden store.
We achieve this in XT by setting the _valid_from
and _valid_to
column
Now if we query in 2024, we still get the 2024 value
But if we query in 2023, we should see the older 2022 value:
If we query in 2020, we should see nothing:
Conclusion
We’ve shown that it’s possible to insert records into the past.
What about if we want to update historical data? How does this work with an immutable database?
Let’s find out in part 4