diff --git a/dbt/include/global_project/macros/adapters/relation.sql b/dbt/include/global_project/macros/adapters/relation.sql index b9af49692..ae1f041dd 100644 --- a/dbt/include/global_project/macros/adapters/relation.sql +++ b/dbt/include/global_project/macros/adapters/relation.sql @@ -7,6 +7,11 @@ {% endmacro %} {% macro make_temp_relation(base_relation, suffix='__dbt_tmp') %} + {#-- This ensures microbatch batches get unique temp relations to avoid clobbering --#} + {% if suffix == '__dbt_tmp' and model.batch %} + {% set suffix = suffix ~ '_' ~ model.batch.id %} + {% endif %} + {{ return(adapter.dispatch('make_temp_relation', 'dbt')(base_relation, suffix)) }} {% endmacro %}