dbt is incorrectly altering my table structure

dbt is changing the definition of my database tables while this is not required. I can see it is trying to execute an ALTER statement to change the type of a column from VARCHAR(255) to VARCHAR(500), although the maximum length of the source column is 98 characters so this is not even required.

I can see why dbt is doing this, because it creates a temporary view based on the model definition and uses this view to insert the data into a temporary table. This table is created with a SELECT * INTO statement, so it leaves the table definition to Azure SQL Server. Then it compares the table definition of this new temporary table to the existing table in the data warehouse (manually created with a DDL) and detects a difference, which dbt thinks it needs to resolve.

I would like to avoid this all together and tell dbt to leave the structure of existing tables alone. The tables have been created with a custom DLL after careful consideration and I know for sure that all source data will fit into these tables. My question is how do I tell dbt to not change the table definitions but just move the data from A to B?

NB: All model materializations are set to “incremental”, so dbt is not dropping and recreating the entire table every time a model is run.

I’m running dbt version 1.3.2 and connection to Azure SQL Server

Did you got any solution for this issue

I am also experiencing the issue where dbt is performing unwanted alterations on column lengths in Snowflake.
If anyone has insights, workarounds, or potential solutions, I would greatly appreciate your input.

Am experiencing same issue with dbt. Can someone please share any solutions we have

I am experiencing the same issue with alter statements, particularly with the varchar datatype that has values other than 16777216 in size, where it updates to 16777216. Is there any fix?

@koenV - dbt, along with the other intermediate operations, compares the data type lengths of the columns between the temp view it creates from dbt Model code with the the DDL deployed in the Database. If in the database your existing table has varchar(250) and dbt Model code has varchar(500) or nothing, then it will run ALTER statement and change the size to the bigger one out of two i.e., varchar(500), leading to change in definition of your DB object. You need to CAST this in your dbt Model with same size as in your DB object. That resolved my issue for now!!