Search code examples
amazon-web-servicesamazon-redshiftsql-delete

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


I have the following query in Redshift:

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

When I try to execute it, it gives me back the warning of the title. However, it does have a where clause, so I am wondering why this appear.

Maybe it is because the where clause makes reference to the query of the join and not the other? If so, how could avoid this warning?


Solution

  • Turns out the solution (for maintaining the join) was to delete the *.

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