diff --git a/.changes/unreleased/Fixes-20241108-154557.yaml b/.changes/unreleased/Fixes-20241108-154557.yaml new file mode 100644 index 000000000..0bc3c9622 --- /dev/null +++ b/.changes/unreleased/Fixes-20241108-154557.yaml @@ -0,0 +1,6 @@ +kind: Fixes +body: Cleans up the temp table created by the merge incremental stratergy when checking the schema +time: 2024-11-08T15:45:57.570611Z +custom: + Author: joshuao11 + Issue: "1389" diff --git a/dbt/include/bigquery/macros/materializations/incremental_strategy/merge.sql b/dbt/include/bigquery/macros/materializations/incremental_strategy/merge.sql index a204caed9..091f7cd91 100644 --- a/dbt/include/bigquery/macros/materializations/incremental_strategy/merge.sql +++ b/dbt/include/bigquery/macros/materializations/incremental_strategy/merge.sql @@ -27,8 +27,12 @@ {% do predicates.append(avoid_require_partition_filter) %} {%- endif -%} - {% set build_sql = get_merge_sql(target_relation, source_sql, unique_key, dest_columns, predicates) %} + -- 1. Run merge statement + {{ get_merge_sql(target_relation, source_sql, unique_key, dest_columns, predicates) }}; - {{ return(build_sql) }} + {% if tmp_relation_exists -%} + -- 2. clean up the temp table if we have used one + drop table if exists {{ tmp_relation }}; + {%- endif -%} {% endmacro %}