我非常喜欢使用 Snowpipe,但在使用它时我无法应用我的 upsert 逻辑。
这就是我的 upsert 逻辑:
create temp table temp_table (like target);
copy into temp_table from @snowflake_stage;
begin transaction;
delete from target using temp_table
where target.pk = temp_table.pk;
insert into target
select * from temp_table;
end transaction;
drop table temp_table;
Run Code Online (Sandbox Code Playgroud)
然而,对于 Snowpipe,我只允许定义单个复制命令,因此我无法执行一系列命令。
我考虑过使用任务和流,但任务似乎不支持事务(每个任务不止一个查询)。我也考虑过使用MERGE,但我必须明确定义我想要的列INSERT。
例如,我不能做类似的事情(插入而不定义要插入的内容):
merge into src using temp_table on src.pk = temp_table.pk
when not matched then insert;
Run Code Online (Sandbox Code Playgroud)
在仍然使用 Snowpipe 的同时,还有其他方法可以更新插入我的数据吗?