如何获取使用上一个UPDATE语句更新的行列表?
例如:
UPDATE test SET title = 'dont delete this' WHERE id IN(1,2,3);
UPDATE test SET deleted = true WHERE id NOT IN last_updated_rows('id');
另外,有没有办法在单个更新语句中执行这样的查询?
答案 0 :(得分:1)
returning
子句专门执行您想要的操作。但你问题中的查询可以用这样的逻辑来处理:
UPDATE test
SET title = (case when id in (1, 2, 3) then 'dont delete this' else title end),
delete = (case when id in (1, 2, 3) then delete else true end);