1

How can I change the default columns name in a snapshot: dbt_valid_from dbt_valid_to?

I override the macro default__build_snapshot_table and it is working the first time, but when I re run the snapshot I am getting the following error:

enter image description here

Adam Kipnis
  • 10,175
  • 10
  • 35
  • 48
  • I've provided an answer that should help you resolve the issue. In the future, please include sample code and not just the error message you're getting. – Adam Kipnis Apr 25 '23 at 15:07

1 Answers1

1

There are 2 macros you need to override. The first (build_snapshot_table) handles the initial creation of the snapshot table, which you've done. The second (build_snapshot_staging_table) handles the delta on subsequent runs. You can see this in the dbt-core/snapshot.sql code (snapshot.sql):

  {% if not target_relation_exists %}


      {% set build_sql = build_snapshot_table(strategy, model['compiled_sql']) %}
      {% set final_sql = create_table_as(False, target_relation, build_sql) %}


  {% else %}


      {{ adapter.valid_snapshot_target(target_relation) }}


      {% set staging_table = build_snapshot_staging_table(strategy, sql, target_relation) %}
...

Take a look at the default implementation to see what logic you need to replace for renaming the columns. Should be pretty straightforward.

Adam Kipnis
  • 10,175
  • 10
  • 35
  • 48