dbt-msft / dbt-sqlserver

dbt adapter for SQL Server and Azure SQL
MIT License
212 stars 99 forks source link

Create table as has extra drop relation statement #488

Closed cody-scott closed 7 months ago

cody-scott commented 7 months ago

Removed the additional drop relation in https://github.com/dbt-msft/dbt-sqlserver/blob/master/dbt/include/sqlserver/macros/materializations/models/table/create_table_as.sql#L12

I don't believe this resolves the issue noted here, but its a good cleanup. https://github.com/dbt-msft/dbt-sqlserver/discussions/481

When running a run with the following model it generates two drops

{{
    config(
        materialized='incremental'
    )
}}

select
    *

from dbo.tst

{% if is_incremental() %}

  -- this filter will only be applied on an incremental run
  -- (uses >= to include records whose timestamp occurred since the last run of this model)
  where DT >= (select DATEADD(MINUTE, -20, max(DT)) from {{ this }})

{% endif %}

DROPS

USE [TestDB];
EXEC('DROP view IF EXISTS "dbt"."incremental_mdl__dbt_tmp_temp_view";');
USE [TestDB];
EXEC('DROP table IF EXISTS "dbt"."incremental_mdl__dbt_tmp";');
schlich commented 7 months ago

Closed by #489

clegendre commented 5 months ago

Hi ! This drop was useful for us. The incremental_mdl__dbt_tmp table stay in the database, and subsequent runs fails.

clegendre commented 5 months ago

Hi and sorry for the reminder, but this is still very annoying. Could you explain why you did remove this extra drop ?

ms32035 commented 4 months ago

@cody-scott @schlich I also see an issue with this. I did an upgrade to the latest dbt-fabric here https://github.com/dbt-msft/dbt-sqlserver/pull/502, and because of this line removed, I have one failing test TestIncrementalGrantsSQLServer