将冲突条款转换为雪花

Converting an on conflict clause to snowflake

如何将以下 Postgres 查询转换为 Snowflake -

INSERT INTO infer (claim_id, patient_id, 

rend, bill, from_date, to_date, diff, dx)
SELECT claim_id, patient_id, rend, bill, from_date, to_date, diff, dx
FROM infer_2021q1
ON CONFLICT (claim_id, rend, bill, from_date, to_date, dx)
DO UPDATE 
SET 
patient_id = excluded.patient_id,
to_rend = excluded.to_rend,
to_bill = excluded.to_bill,
diff = excluded.diff

在 Postgres 中,我能够 运行 这是因为 on conflict 子句中的列是唯一索引。但是 Snowflake 没有索引,所以不确定如何 运行 在合理的时间和资源利用率内进行这样的查询。

Snowflake 支持 MERGE 语句:

Inserts, updates, and deletes values in a table based on values in a second table or a subquery. This can be useful if the second table is a change log that contains new rows (to be inserted), modified rows (to be updated), and/or marked rows (to be deleted) in the target table.

MERGE INTO infer 
USING infer_2021q1
  ON infer.claim_id = infer_2021q1.rend
AND infer.bill = infer_2021q1.bill 
AND infer.from_date =infer_2021q1.from_date 
AND infer.to_date = infer_2021q1.to_date 
AND infer.dx = infer_2021q1.dx 
WHEN MATCHED THEN 
  SET patient_id = infer_2021q1.patient_id,
     to_rend = infer_2021q1.to_rend,
     to_bill = infer_2021q1.to_bill,
     diff = infer_2021q1.diff
WHEN NOT MATCHED THEN
  INSERT infer (claim_id, patient_id, rend, bill, from_date, to_date, diff, dx)
  VALUES (infer_2021q1.claim_id, infer_2021q1.patient_id, infer_2021q1.rend,
         infer_2021q1.bill, infer_2021q1.from_date, infer_2021q1.to_date,
         infer_2021q1.diff, infer_2021q1.dx);