Merge command syntax in Snowflake

Inserts, updates, and deletes values in a table based on values in a second table

merge into t1 using t2 on t1.t1key = t2.t2key
when matched and t2.marked = 1 then delete
when matched then update set val = t2.newval
when not matched then insert (val, status) values (t2.newval, t2.newstatus);

nVector

posted on 04 Oct 19

Enjoy great content like this and a lot more !

Signup for a free account to write a post / comment / upvote posts. Its simple and takes less than 5 seconds




ssgr199324-Jan-21

Hello,

Since Snowflake not supporting OUTPUT clause, could you please help me with sample SCD-2 code in snowflake.

nVector26-Jan-21

Can you elaborate on what you mean by OUTPUT Clause ?  To Achieve SCD2,

  • If you have data in stage table you can directly update the target table to close the existing record. 
  • And then do a fresh insert from the STG to Target