雪花插入匹配或更新为不匹配



有没有办法在雪花中插入匹配或更新不匹配?

文档指出:

The command supports semantics for handling the following cases:
Values that match (for updates and deletes).
Values that do not match (for inserts).

https://docs.snowflake.com/en/sql-reference/sql/merge.html

但是我既需要update又需要insert,确切地matchednot matched哪个条款并不重要。

谢谢。

====== 更新 ====== 这是我想要实现的目标:

merge into target_table using source_table 
on target_table.id = source_table.id
when matched and condition = 1 then 
update set target_table.description = source_table.description
when matched and condition != 1 then 
update set target_table.description = source_table.description
insert <some data>
when not matched 
insert <some data>;

通过创建两个流和两个单独的合并语句来解决。

merge into target_table using source_table 
on target_table.id = source_table.id
when matched and condition = 1 then 
update set target_table.description = source_table.description
when matched and condition != 1 then 
update set target_table.description = source_table.description
merge into target_table using source_table 
on condition = 1
when not matched 
insert <some data>;

最新更新