mysql table column named ‘default’ not working!
Sunday, April 19th, 2009I was having a hard time figuring out what the problem with my mysql query was, and so this might help someone.I had a column named in my table called ‘default’ which was just a tinyint (or boolean) 1 or 0 so that I could indicate if the row was meant to be the default row for a page. However my query that said:
“select * from table where default=1″
Wasn’t working at all.It was giving me the same unhelpful error “you have an error in your SQL syntax. Check the manual blablabla”.Then I rememberd that the word “default” in mysql syntax is used to specify what you want the default value to be for a column when you are setting up a new one.
So if you use it as a column name it wont work and will go mental.I then changed it to be “isdefault” and it worked fine.It soon came to my attention that it’s a really dumb idea to label your column names anything that might conflict with some mysql query code.
In the same way it wouldn’t make sense to name a column “where” or “select” or “update” or any other mysql syntaxy word.But you probably aren’t idiots and already know this….