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

t8e9dugd  于 2021-08-01  发布在  Java
关注(0)|答案(1)|浏览(318)

有没有办法在snowflake中插入匹配的或更新不匹配的?
文件规定:

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 ,而具体哪个子句并不重要 matched 或者 not 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>;
pexxcrt2

pexxcrt21#

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

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>;

相关问题