我试图在 Rails 查询中将整数转换为字符串。比如我要复制这条SQL
SELECT CAST(id AS CHAR) FROM `articles` WHERE `articles`.`name` = 'Frustrated';
这选择了id
Article.where( name: "Frustrated" ).select("id")
但是这个死了
Article.where( name: "Frustrated" ).select("CAST (id AS CHAR) ")
即使 SQL 看起来相同。
是否可以这样做,我做错了什么?
最佳答案
只是错误位置的空格。这行得通
Article.where( name: "Frustrated" ).select("CAST(id AS CHAR)")
关于mysql - 将整数转换为字符串 - rails - mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10930846/