【发布时间】:2019-12-24 16:15:12
【问题描述】:
create table tab(id int);
insert into tab(id) values(1);
with x as (delete from tab where id = 1 returning id),
y as (select * from tab where id in (select id from x))
select * from y;
-- outputs a row with "1"
-- i need no rows returned
为什么在y CTE 子查询中仍然看到已删除的行? x 和 y 部分应按顺序执行,因为 y 依赖于 x。您能否向我解释一下为什么我看不到 x 的变化?我应该怎么做才能见到他们?
我不确定它是否与隔离级别有关,因为一切都在同一个查询中完成 => 同一个事务
谢谢!
【问题讨论】:
标签: sql postgresql common-table-expression