Skip to content
BENIBIX Learn

dbt Snapshot

Data⚙️ ProcessingData Transformation

Also known as dbt Snapshots

A dbt table that keeps each old version of a row that changes.

Think of it like

It is like a height chart on a door frame. Each new mark is added, and the old marks stay.

Example

An order goes from pending on 1 January to shipped on 2 January. The snapshot keeps both rows, each with the dates it was true.

Why it matters

Many source tables overwrite old values. Without a snapshot, the past is gone for good.

Definition

A dbt snapshot keeps the history of a table whose rows change in place. Each time dbt snapshot runs, it compares the table with the last run. When a row has changed, it closes the old version and adds the new one. Two columns, dbt_valid_from and dbt_valid_to, say when each version was true. This builds a type 2 slowly changing dimension.

Example code

yaml
snapshots:
  - name: orders_snapshot
    relation: source('shop', 'orders')
    config:
      unique_key: id
      strategy: timestamp
      updated_at: updated_at
This uses the timestamp strategy. A row counts as changed when its updated_at time moves on.
The snapshot reads the source and keeps each old version of a row.

Common mistake

Running it too rarely. A row that changes twice between runs keeps only the last change.

Key takeaways

  1. 1
    Never overwrite. A change adds a row.
  2. 2
    Valid from and to. Each version has its own dates.
  3. 3
    Run on a schedule. Only changes seen at a run are kept.

Compare