简体   繁体   中英

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!

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';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM