Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/60.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
MySQL按布尔值tinyint排序_Mysql_Sql_Ruby On Rails_Postgresql_Innodb - Fatal编程技术网

MySQL按布尔值tinyint排序

MySQL按布尔值tinyint排序,mysql,sql,ruby-on-rails,postgresql,innodb,Mysql,Sql,Ruby On Rails,Postgresql,Innodb,我正在使用mysql版本14.14发行版5.5.31,用于debian linux gnu(x86_64) 此查询失败,出现错误,您的SQL语法[…]在“read ASC”附近出现错误。消息: SELECT 'messages'.* FROM 'messages' WHERE 'messages'.'user_id' = 2 ORDER BY read ASC; 其中,read列是由Rails ActiveRecord接口生成的用于存储布尔值的TINYINT(1)值 切换到postgresql

我正在使用mysql版本14.14发行版5.5.31,用于debian linux gnu(x86_64)

此查询失败,出现
错误,您的SQL语法[…]在“read ASC”附近出现错误。
消息:

SELECT 'messages'.* FROM 'messages' WHERE 'messages'.'user_id' = 2 ORDER BY read ASC;
其中,
read
列是由Rails ActiveRecord接口生成的用于存储布尔值的
TINYINT(1)

切换到postgresql时也可以执行相同的操作,但我目前无法访问pg生成的查询。
实际查询是否有问题?(也许我不能点菜)或者我应该提交一份bug报告吗?

Read是mysql中的reserve关键字

您必须在查询中添加'read'ASC

问题是“read”在mysql中是一个关键字。最好避免使用保留字作为列标识符

您可以将其与backticks一起使用

ORDER BY `read' ASC

除了@naveen的答案外,您还需要:

更好的是,不要使用MySQL保留字作为列名。要更改名称,请使用
ALTER

ALTER TABLE messages CHANGE read seen TINYINT

实际代码使用反勾号,这是一个输入错误。感谢“看到”的建议,我真的被困在寻找一个好的重命名!
ALTER TABLE messages CHANGE read seen TINYINT