Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update snapshots.md #6866

Merged
merged 6 commits into from
Feb 4, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions website/docs/docs/build/snapshots.md
Original file line number Diff line number Diff line change
Expand Up @@ -346,14 +346,14 @@ snapshots:

</VersionBlock>

#### Example usage with `check_cols: updated_at`
#### Example usage with `updated_at`

When using the `check` strategy, dbt tracks changes by comparing values in `check_cols`. You can use an `updated_at` column to detect when a row has changed.
When using the `check` strategy, dbt tracks changes by comparing values in `check_cols`. By default, dbt uses the timestamp to update `dbt_updated_at`, `dbt_valid_from` and `dbt_valid_to` fields. Optionally you can set an `updated_at` column:

- If `check_cols: updated_at` is set, dbt only tracks changes in that column.
- If `updated_at` isn't included, dbt defaults to using the current timestamp.
- If `updated_at` is configured, the `check` strategy uses this column instead, as with the timestamp strategy.
- If `updated_at` value is null, dbt defaults to using the current timestamp.

Check out the following example, which shows how to use the `check` strategy with `updated_at` using `check_cols`:
Check out the following example, which shows how to use the `check` strategy with `updated_at`:

```yaml
snapshots:
Expand All @@ -364,13 +364,16 @@ snapshots:
unique_key: order_id
strategy: check
check_cols:
- updated_at
- status
- is_cancelled
updated_at: updated_at
```

In this example:

- `check_cols: updated_at` makes sure that only the `updated_at` column triggers new snapshots.
- If at least one of the specified `check_cols `changes, the snapshot creates a new row. If the `updated_at` column has a value (is not null), the snapshot uses it; otherwise, it defaults to the timestamp.
- If `updated_at` isn’t set, then dbt automatically falls back to [using the current timestamp](#sample-results-for-the-check-strategy) to track changes.
- Use this approach when your `updated_at` column isn't reliable for tracking record updates, but you still want to use it &mdash; rather than the snapshot's execution time &mdash; whenever row changes are detected.

### Hard deletes (opt-in)

Expand Down
Loading