diff --git a/core/dbt/include/global_project/macros/etc/is_incremental.sql b/core/dbt/include/global_project/macros/etc/is_incremental.sql index d28a6a44cb2..f3897294a13 100644 --- a/core/dbt/include/global_project/macros/etc/is_incremental.sql +++ b/core/dbt/include/global_project/macros/etc/is_incremental.sql @@ -5,6 +5,6 @@ {{ return(False) }} {% else %} {% set relation = adapter.get_relation(this.database, this.schema, this.table) %} - {{ return(relation is not none and not flags.FULL_REFRESH) }} + {{ return(relation is not none and relation.type == 'table' and not flags.FULL_REFRESH) }} {% endif %} {% endmacro %} diff --git a/test/integration/035_changing_relation_type_test/models/model.sql b/test/integration/035_changing_relation_type_test/models/model.sql index 05b4efd430d..c88e66ee170 100644 --- a/test/integration/035_changing_relation_type_test/models/model.sql +++ b/test/integration/035_changing_relation_type_test/models/model.sql @@ -2,3 +2,7 @@ {{ config(materialized=var('materialized')) }} select '{{ var("materialized") }}' as materialization + +{% if var('materialized') == 'incremental' and is_incremental() %} + where 'abc' != (select max(materialization) from {{ this }}) +{% endif %}