diff --git a/.changes/unreleased/Fixes-20231020-112317.yaml b/.changes/unreleased/Fixes-20231020-112317.yaml new file mode 100644 index 00000000..e104af44 --- /dev/null +++ b/.changes/unreleased/Fixes-20231020-112317.yaml @@ -0,0 +1,7 @@ +kind: Fixes +body: Fix materialized view cleanup bug. +time: 2023-10-20T11:23:17.134994-04:00 +custom: + Author: wjhrdy + Issue: "366" + PR: "367" diff --git a/dbt/include/trino/macros/materializations/materialized_view.sql b/dbt/include/trino/macros/materializations/materialized_view.sql index 897b810a..6bee70bb 100644 --- a/dbt/include/trino/macros/materializations/materialized_view.sql +++ b/dbt/include/trino/macros/materializations/materialized_view.sql @@ -13,10 +13,10 @@ {% if existing_relation is not none %} {{ log("Found a " ~ existing_relation.type ~ " with same name. Will drop it", info=true) }} - alter {{ existing_relation.type|replace("_", " ") }} {{ existing_relation }} rename to {{ backup_relation.include(database=False, schema=False) }}; + alter {{ existing_relation.type|replace("_", " ") }} {{ existing_relation }} rename to {{ backup_relation }}; {% endif %} - alter materialized view {{ intermediate_relation }} rename to {{ relation.include(database=False, schema=False) }}; + alter materialized view {{ intermediate_relation }} rename to {{ relation }}; {% endmacro %}