Thursday 24 May 2007

MySQL annoyance

Got bitten by a bit of insanity in MySQL 5.0.26. Imagine you have a bogus query, SELECT poo FROM SomeTable, that looks correct, except that there is no "poo" column in the said table. (You mispelled "foo". So much for your brain.) MySQL will correctly return an error, Unknown column or somesuch, when you try to run it.

Except in a subquery. Like, for example, in:

DELETE FROM SomeOtherTable WHERE id IN (SELECT poo FROM SomeTable)
which will be then exactly equivalent to a simple, unadorned DELETE FROM SomeOtherTable. And you loose your data.

No comments: