Snowflake – Maintaining Partitions in Tables with Delete / Insert Into Instead of Create or Replace Table

Often times we need to update tables in Snowflake and maintain partitions. We can do this with a Delete (by dt partition) and Insert Into (where dt = current dt you are trying to update) instead of Create or Replace Table command (which will not handle partitions).

I.e.

Instead of:

create or replace table new_table
as
select * from some_table

We can do this instead to handle partitions:

delete from new_table
where dt='{DT}'

insert into new_table
as
select *
from some_table
where dt = '{DT}'

Leave a Reply