Search code examples
mysqlsqlenumsreserved-words

MySQL query with enum values


I've the following structure in MySQL 5.6.19.

CREATE TABLE `metadata` (
`md5` char(32) NOT NULL,
`match` enum('none','md5','similarity') DEFAULT NULL
) 

And I got an error doing a query like this:

select * from metadata where match = 'md5';

The error is:

ERROR 1064 (42000): 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 '= 'md5'' at line 1

There're multiple entries in the table and rows that could match the query. But MySQL refuse to do it. Any idea about the reason? Thanks!


Solution

  • MATCH is reserved keyword in MySQL: http://dev.mysql.com/doc/mysqld-version-reference/en/mysqld-version-reference-reservedwords-5-5.html. You should enclose your field name in backticks to make it work:

    select * from metadata where `match` = 'md5';