The problem I’m having
I am trying to implment a model that merges data into a target table. The target contains an audit field that is not in the source data: last_updated. I would like this field to be set to the current time whenever a row is inserted into or updated in the target.
The context of why I’m trying to do this
I want to reflect the last time a row was updated (or inserted).
What I’ve already tried
{{
config(
alias='dbt_scd_1_target',
materialized='incremental',
unique_key='my_bk',
incremental_strategy='merge',
merge_exclude_columns = ['last_updated'],
)
}}
select
s.*,
systimestamp() last_updated
from
dbt_scd_1_source s
This works for rows that are inserted, but not for those that are updated.