简体   繁体   English

如何仅替换/覆盖雪花表中的某些值?

[英]How to Replace/Overwrite only certain values in Snowflake Table?

I have a Snowflake SQL command in the form of:我有一个 Snowflake SQL 命令,格式如下:

CREATE TASK REPLACE_CERTAIN_ROWS
WAREHOUSE=<MY_WAREHOUSE>
SCHEDULE='USING CRON 0 5,17 * * * UTC'
AS
insert overwrite into <MY_SCHEMA>.<MY_TABLE>(FIELD1,FIELD2)
<MY_SQL>

And my table looks like:我的桌子看起来像:

FIELD1|FIELD2
ABC,REPLACE
DEF,REPLACE
GHI,DONTREPLACE
JKL,DONTREPLACE

Instead of replacing the entire table how can I alter my Snowflake to only overwrite the FIELD2="REPLACE" rows?我怎样才能改变我的雪花以仅覆盖 FIELD2="REPLACE" 行,而不是替换整个表? Do I have to first have a command that deletes these rows or is there a way to do it more instantaneously?我是否必须首先有一个删除这些行的命令,或者有没有办法更即时地做到这一点? I know I can only execute one command per Snowflake task so would like to avoid managing dependent tasks and do it all in the same task/command.我知道每个 Snowflake 任务只能执行一个命令,因此希望避免管理依赖任务并在同一个任务/命令中完成所有操作。

Desired Result:期望的结果:

FIELD1|FIELD2
GHI,DONTREPLACE <- remained
JKL,DONTREPLACE <- remained
MNO,REPLACE <- was replaced
PQR,REPLACE <- was replaced

UPDATE is the normal way to do this: UPDATE是执行此操作的正常方法:

UPDATE <MYDB>.<MY_SCHEMA>.<MY_TABLE> SET field1 = <new value> WHERE field2 = 'REPLACE';

but if you are trying to drive this from a TABLE/STREAM then MERGE is more what you will want.但是,如果您尝试从 TABLE/STREAM 驱动它,那么MERGE将是您想要的更多。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM