DBT : DBTs strategy on drop and create the target table on each run

getDbt

The behavior of dbt with respect to dropping and creating the target table on each run depends on the materialization strategy that you use for your dbt models.

By default, when you define a model in dbt, it is created as a “view” materialization. In this mode, dbt does not drop or recreate the target table on each run, but instead creates a view that references the data in the target table. This approach is typically used for models that reference data that is managed outside of dbt, such as tables that are created and managed by other ETL tools or applications.

However, if you want to overwrite the data in the target table with the results of your dbt model, you can use a different materialization strategy, such as “table” or “incremental”. In this mode, dbt will drop and recreate the target table on each run, populating it with the results of the model.

For example, if you define a model with a “table” materialization like this:

-- my_table.sql
{{
  config(
    materialized='table'
  )
}}

select *
from my_source_table

On the first run of dbt run, dbt will create a new table in the target database called my_table and populate it with the results of the my_source_table query. On subsequent runs of dbt run, dbt will drop and recreate the my_table table before populating it with the results of the query again.

Overall, the behavior of dbt with respect to dropping and creating the target table on each run depends on the materialization strategy that you use for your dbt models, and can be customized to fit the needs of your specific use case.

Get more useful articles on dbt

  1. ,
Author: user

Leave a Reply