问题描述
Kudu是否支持UPDATE
的{{1}}部分的条件?
我可以提供条件子句以仅基于插入值和目标表之间的比较来更新给定值吗? 实际用例是使用最新的时间戳列更新。
这是我想象中的行为。
UPSERT INTO
如果不存在3,则应插入。
解决方法
我发现一个解决方案是使用LEFT JOIN
并在SELECT
表达式中进行过滤。因此,假设我们有一个与目标表相同的表to_upsert
,并且我们所有潜在的高置信度...
INSERT INTO to_upsert VALUES (3,"bobby" 100),(5,"newgal",600);
UPSERT INTO my_first_table
SELECT to_upsert.id,to_upsert.name,to_upsert.status
FROM to_upsert
LEFT JOIN my_first_table ON to_upsert.id = my_first_table.id
WHERE my_first_table.status > to_upsert.status OR my_first_table.id IS NULL;
SELECT * FROM my_first_table;
+----+--------+--------+
| id | name | status |
+----+--------+--------+
| 3 | bobby | 100 |
| 1 | lee | 101 |
| 2 | shiv | 102 |
| 5 | newgal | 600 |
+----+--------+--------+
感谢您收看这一集,观看我学习sql。