# Recreate SCD2 table with snapshots

**URL:** <https://discourse.getdbt.com/t/recreate-scd2-table-with-snapshots/15297>\
**Category:** Help\
**Tags:** snapshots\
**Created:** [September 8, 2024, 4:22pm UTC](https://discourse.getdbt.com/t/recreate-scd2-table-with-snapshots/15297 "2024-09-08T16:22:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![oliveirajo](https://sea2.discourse-cdn.com/flex020/user_avatar/discourse.getdbt.com/oliveirajo/32/4576_2.png) [@oliveirajo](https://discourse.getdbt.com/u/oliveirajo)\
**Post date:** [September 8, 2024, 4:22pm UTC](https://discourse.getdbt.com/t/recreate-scd2-table-with-snapshots/15297/1 "2024-09-08T16:22:44Z")

</div>

## Unable to recreate SCD2 table (updated\_At, valid\_from, valid\_to with todays date)

## Hello, we are migrating our ETL jobs to dbt, and we are on the point where we need/want to migrate our scd2 tables. Wondering what can be the best option and taking in consideration that we have a few extraction files (full extraction so timestamp strategy won’t be applicable).

Also I would like to have a plan to when, (for some reason) I need to recreate SCD2 tables I might be able to do it.

We have python script that will execute dbt snapshot on each different date that we have on our source table (weekly FULL SNAPSHOTS). “simulating” the insertion. However we are unable to adapt the dbt\_updated\_at, dbt\_valid\_from and dbt\_valid\_to to the respective dates, meaning that they are all getting timestamps from the current date.

Hoping to have a few insights from your side !

Appreciate !

---

<div class="post-metadata">

**Author:** ![keithfajardo](https://sea2.discourse-cdn.com/flex020/user_avatar/discourse.getdbt.com/keithfajardo/32/4422_2.png) [@keithfajardo](https://discourse.getdbt.com/u/keithfajardo)\
**Post date:** [September 9, 2024, 12:51am UTC](https://discourse.getdbt.com/t/recreate-scd2-table-with-snapshots/15297/2 "2024-09-09T00:51:25Z")

</div>

Hi, @oliveirajo

Hmm what snapshot strategy are you using?

---

<div class="post-metadata">

**Author:** ![oliveirajo](https://sea2.discourse-cdn.com/flex020/user_avatar/discourse.getdbt.com/oliveirajo/32/4576_2.png) [@oliveirajo](https://discourse.getdbt.com/u/oliveirajo)\
**Post date:** [September 16, 2024, 12:28pm UTC](https://discourse.getdbt.com/t/recreate-scd2-table-with-snapshots/15297/3 "2024-09-16T12:28:24Z")

</div>

We are using “check strategy”.

We are setting up a dbt snapshot to migrate to dbt.

We have a table with weekly extractions from a source system, and we need to build now a scd2 table.

Since the upstream have a column named “extraction\_date”, we though about using the “check” strategy to control it and use a variable with the dbt snapshot where we could easily pass the different dates to recreate a scd2 table.

However we noticed the cols generated by dbt : dbt\_updated\_at, dbt\_valid\_from e dbt\_valid\_to are taking into consideration today’s date (execution date timestamps).

Can we force dbt to change the dates that he takes into consideration ?

I think that this might be very useful even when, for example, the scheduled execution, during a weekend failed, and on Monday we need to re-launch the pipeline from Saturday…

Maybe there is another approach that I’m missing here.

Is it possible to set the dbt\_valid\_from and the dbt\_valid\_to in a way that reflects the date we snapshot.

Thanks for your help!

---

<div class="post-metadata">

**Author:** ![dnewton\_nouria](https://avatars.discourse-cdn.com/v4/letter/d/76d3ee/32.png) [@dnewton\_nouria](https://discourse.getdbt.com/u/dnewton_nouria)\
**Post date:** [September 17, 2024, 1:46pm UTC](https://discourse.getdbt.com/t/recreate-scd2-table-with-snapshots/15297/4 "2024-09-17T13:46:04Z")

</div>

I have the same question. Sometimes you have a data source that has a changelog (like an effective date for each row change), but it’s not a full SCD source with end dates and so on. You’d want to feed this into a snapshot process and have it use the incoming data’s data-change date as the dbt\_valid\_from date, and let dbt manage the rest…
