When my script ends up building a query resulting in an empty set, such as for example:
select name
from customers
where id in()
limit 0,30
Why do I get:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') LIMIT 0, 30' at line 1
I expect it to return an empty result set, not a syntax error.
You may ask "hell, you shouldn't even run the query in that case", and it may be partially true, but techincally, I don't see anything wrong in that query, it would be the same as doing:
select name
from customers
where 0
It's stupid, but MySQL doesn't fire a syntax error in that case.
The reason I often end up with "in ()" is becasue in PHP I do an implode of an array to retrive IDs to enclose in between ( ), but sometimes the array is empty and nothing get printed inside. I obviously could test the emptiness of the array before, but I'm just curious about the decision of the devs of throwing a syntax error when I put nothing between ( ).
Thank you.