为什么不安全查询:不带where的删除语句会清除table中的所有数据?

Why Unsafe query: Delete statement without where clears all data in the table?

我在 Redshift 中有以下查询:

delete * from a
left join s on a.order_id = s.id
where s.order_id is not null

当我尝试执行它时,它返回标题的警告。但是,它确实有一个 where 子句,所以我想知道为什么会出现这种情况。

可能是因为 where 子句引用了连接的查询而不是其他?如果是这样,如何避免这个警告?

您可以尝试重写它,例如:

DELETE FROM a
WHERE a.order_id IN (SELECT DISTINCT id FROM other_table)

原来解决方案(用于维护连接)是删除 *

delete from a
left join s on a.order_id = s.id
where s.order_id is not null