I don't want dbt to change the column type of an existing table that's loaded incrementally

We’re migrating transformation scripts from a legacy ETL tool to dbt but when I apply the incremental strategy, dbt tries to run an ALTER COLUMN statement to change the data type of the column (specifically VARCHAR(2) → VARCHAR(4)). How can I prevent dbt from trying to make this change?

I’ve tried specifying the column type in the _model.yml file as VARCHAR(2) but that doesn’t work. For some reason when the temp incremental table is created, it automatically elects that column to be VARCHAR(4)

Hi Paul,
I’ll see this at times and the solution I use is to make sure that your select statement (the sql in your model) is casting the value appropriately. Your data platform will infer a data type when it selects, in your case it is inferring varchar(4). Explicitly cast that field as varchar(2) in your sql and it will line up. You can run into this when you define contracts on models. Your contract says one data type, but your sql resolves to another and it creates an error.

Note: @Treven Mull originally posted this reply in Slack. It might not have transferred perfectly.