MySQL Forums :: General :: Why does "in ()" give syntax error?


Advanced Search

Why does "in ()" give syntax error?
Posted by: Dr Lightman ()
Date: October 23, 2010 06:31AM

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.

Options: ReplyQuote


Subject Written By Posted
Why does "in ()" give syntax error? Dr Lightman 10/23/2010 06:31AM
Re: Why does "in ()" give syntax error? Peter Brawley 10/23/2010 08:12AM
Re: Why does "in ()" give syntax error? Dr Lightman 10/23/2010 09:52AM
Re: Why does "in ()" give syntax error? Peter Brawley 10/23/2010 10:45AM
Re: Why does "in ()" give syntax error? Dr Lightman 10/23/2010 11:37AM
Re: Why does "in ()" give syntax error? Chad Bourque 10/23/2010 11:39AM
Re: Why does "in ()" give syntax error? Dr Lightman 10/25/2010 05:26AM
Re: Why does "in ()" give syntax error? Chad Bourque 10/25/2010 08:09AM
Re: Why does "in ()" give syntax error? Dr Lightman 10/27/2010 04:12AM
Re: Why does "in ()" give syntax error? Peter Brawley 10/27/2010 09:02AM
Re: Why does "in ()" give syntax error? Rick James 11/02/2010 02:13PM
Re: Why does "in ()" give syntax error? Ashley Stern 10/28/2010 04:06AM
Re: Why does "in ()" give syntax error? Peter Brawley 10/28/2010 10:11AM
Re: Why does "in ()" give syntax error? Jeremy Higgins 10/23/2010 04:59PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.