mysql - 将整数转换为字符串 - rails - mysql

标签 mysql ruby-on-rails casting

我试图在 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/

相关文章:

php - 数组序列化问题

ruby-on-rails - Ruby 检查日期时间是否为 iso8601 并保存

ruby-on-rails - 使用 Rails 生成器修改现有文件?

Dynamic_cast 的 C++ 安全替代方案

ios - 如何在单个变量中分配不同类型?

c++ - 将 `unsigned char` 放入 `char`

php - 在使用 ini_set ('max_execution_time' , 0);

mysql - 在子查询中访问父查询变量

mysql - ionic : sqLite & PouchDB or NoSQL

ruby-on-rails - 在 Heroku 上使用 texticle 与 postgresql 全文搜索进行部分匹配