这两个sql都可以执行,第一个删除所有,第二个是逻辑对。
第一个
with d0 as (
delete from seller_create_request
where seller_id in
(
select id
from seller
where email in
('[email protected]')
)
returning seller_create_request.seller_id
)
delete from seller
where id in (select id from d0)
returning seller.id;
第二个
with d0 as (
delete from seller_create_request
where seller_id in
(
select id
from seller
where email in
('[email protected]')
)
returning seller_create_request.seller_id
)
delete from seller
where id in (select d0.seller_id from d0)
returning seller.id
;
第一个select id from d0
似乎等于select id from seller
。我的初衷是select seller_id from d0
拼写错误。它不会导致
column id does not exist
因为它从 d0 开始。
所以我很奇怪为什么 psql 有这种行为,我从简单的理解中遗漏了什么?