如何將以下 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 沒有索引,因此不確定如何在合理的時間和資源利用率內運行這樣的查詢。
uj5u.com熱心網友回復:
Snowflake 支持MERGE陳述句:
根據第二個表或子查詢中的值插入、更新和洗掉表中的值。如果第二個表是包含目標表中的新行(要插入)、修改的行(要更新)和/或標記的行(要洗掉)的更改日志,這將很有用。
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);
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/451185.html
標籤:sql PostgreSQL 雪花云数据平台
