我想知道是否可以添加某种检查,以便在更新部分成功时中止数据修改 CTE。附件是代表问题的最小查询。如果Updated_rows尚未更新 WHERE IN 子句中指定的 3 行,我希望查询失败。
如果将此查询重写为交互式事务,则很容易实现这一点,但我想知道是否可以在将事物保留为单个数据修改 CTE 的同时实现此目的。
with updated_rows as (
update some_table
set status = 'SUCCEEDED'
where id in ('a', 'b', 'c') and status = 'PENDING'
returning *
), more_updated_rows as (
update another_table
set total = total + 3
where completed = false
returning *
) select * from more_updated_rows