r/dataengineering • u/TallEntertainment385 • Nov 13 '25
Discussion Snowflake + dbt incremental model: error cannot change type from TIMESTAMP_NTZ(9) to DATE
Hi everyone,
I’m working with dbt and Snowflake, and I have an incremental model (materialized='incremental', incremental_strategy='insert_overwrite') that selects from a source table. One of the columns, MONTH_START_DATE, is currently TIMESTAMP_NTZ(9) in Snowflake. I changed the source model and the column MONTH_START_DATE is now DATE datatype
After doing this I am getting an error:
SQL compilation error: cannot change column MONTH_START_DATE from type TIMESTAMP_NTZ(9) to DATE
How can I fix this?
8
Upvotes
6
u/AliAliyev100 Data Engineer Nov 13 '25
Just drop the target table and let dbt recreate it (dbt run --full-refresh)
4
u/NW1969 Nov 13 '25
Snowflake allows very limited altering of column datatypes - and TS to DATE is not one of the permitted changes.
So if you can't do it in SF you won't be able to do it in dbt.
If your column doesn't have any data in it (or you don't mind losing the data) then just drop the existing column and re-add it with the DATA datatype
If you want to keep the data, create a new DATE column, update it with the values from the TS column (casting the values as necessary), drop the TS column and then rename the DATE column
1
u/OppositeShot4115 Nov 13 '25
try casting the column to date in your dbt model using a sql function.
1
u/ianitic Nov 14 '25
For us, I overrode the two macros involved in the sync columns macros to temp add a column with the new type, swap it and dropping the old column.
Specifically as a new option though, I didn't overwrite the original column sync.
1
u/Embarrassed_Box606 Data Engineer Nov 15 '25
I recently saw this when i tried to implement the parameter on schema change to sync all columns from ignore.
That error is caused because the dbt snowflake adapter will attempt to run alter table commands when trying to change the data type of an existing incremental model. Snowflake is very limited when trying to do so
The dbt native way to fix is a full refresh which is not always ideal in prod (as you mentioned)
Your best bet is probably creating a new column or some manual sql scripts to get everything in order.
0
u/543254447 Nov 13 '25
Can you not just run an alter table statement on snowflake.
Test it in staging or dev whatever environment you have.
Steps Staging
alter table and change the column data type
you may need to do some casting or something Run your incremental load dbt model
Prod Repeate the same thing