一个简单的“从代理中选择二进制”查询怎么会有语法错误?

时间:2014-09-19 20:10:56

标签: mysql mariadb

我很困惑为什么这个简单的SQL查询会出现语法错误。 binary是保留字吗?如果是这样,我该如何处理?

show tables
+-------------------------------+
| Tables_in_neutron             |
+-------------------------------+
| agents                        |
              ...
| vips                          |
+-------------------------------+
desc agents
+---------------------+---------------+------+-----+---------+-------+
| Field               | Type          | Null | Key | Default | Extra |
+---------------------+---------------+------+-----+---------+-------+
| id                  | varchar(36)   | NO   | PRI | NULL    |       |
| agent_type          | varchar(255)  | NO   |     | NULL    |       |
| binary              | varchar(255)  | NO   |     | NULL    |       |
| topic               | varchar(255)  | NO   |     | NULL    |       |
| host                | varchar(255)  | NO   |     | NULL    |       |
| admin_state_up      | tinyint(1)    | NO   |     | NULL    |       |
| created_at          | datetime      | NO   |     | NULL    |       |
| started_at          | datetime      | NO   |     | NULL    |       |
| heartbeat_timestamp | datetime      | NO   |     | NULL    |       |
| description         | varchar(255)  | YES  |     | NULL    |       |
| configurations      | varchar(4095) | NO   |     | NULL    |       |
+---------------------+---------------+------+-----+---------+-------+
select binary from agents
ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'from agents' at line 1

由于

1 个答案:

答案 0 :(得分:1)

是的,BINARY是一个保留字。它是一种数据类型,因为@BenaminS链接到。

您可以通过在后引号中分隔保留字来使用保留字(如果设置SQL_MODE = ANSI OR ANSI_QUOTES,则可以使用双引号)。定界标识符还允许您在标识符中使用特殊字符和空格。

您可以在此处查看MySQL的保留字列表:http://dev.mysql.com/doc/refman/5.6/en/reserved-words.html