dbt-msft / dbt-sqlserver

dbt adapter for SQL Server and Azure SQL
MIT License
205 stars 96 forks source link

error when changing model materialization from view to table #509

Closed sinia closed 1 week ago

sinia commented 1 month ago

After running a model materialized as a view, cannot run the same model with table materialization. {{ config(materialized="view") }} --> {{ config(materialized="table") }}

I include example log below. It seems that dbt when rerunning the model incorrectly issues DROP TABLE command although it should DROP VIEW instead.

(venv) >dbt run
13:47:57  Running with dbt=1.7.17
13:47:58  Registered adapter: sqlserver=1.7.4
13:47:58  Found 2 models, 4 tests, 0 sources, 0 exposures, 0 metrics, 447 macros, 0 groups, 0 semantic models
13:47:58
13:47:59  Concurrency: 1 threads (target='dev')
13:47:59
13:47:59  1 of 2 START sql table model schema_dbt.my_first_dbt_model ..................... [RUN]
13:47:59  1 of 2 ERROR creating sql table model schema_dbt.my_first_dbt_model ............ [ERROR in 0.44s]
13:47:59  2 of 2 SKIP relation schema_dbt.my_second_dbt_model ............................ [SKIP]
13:47:59
13:47:59  Finished running 1 table model, 1 view model in 0 hours 0 minutes and 1.12 seconds (1.12s).
13:48:00  
13:48:00  Completed with 1 error and 0 warnings:
13:48:00
13:48:00    Database Error in model my_first_dbt_model (models\example\my_first_dbt_model.sql)
  ('42000', "[42000] [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Cannot use DROP TABLE with 'schema_dbt.my_first_dbt_model__dbt_backup' because 'schema_dbt.my_first_dbt_model__dbt_backup' is a view. Use DROP VIEW. (3705) (SQLMoreResults)")
  compiled Code at target\run\my_dbt_test_project\models\example\my_first_dbt_model.sql
13:48:00
13:48:00  Done. PASS=0 WARN=0 ERROR=1 SKIP=1 TOTAL=2
sinia commented 1 month ago

by the way, no such issue when using dbt-sqlserver=1.4.3

cody-scott commented 1 week ago

closed by #521