Reputation: 3499
I'm trying to cast an integer as a string in a rails query. For example, I want to replicate this SQL
SELECT CAST(id AS CHAR) FROM `articles` WHERE `articles`.`name` = 'Frustrated';
This selects the id
Article.where( name: "Frustrated" ).select("id")
But this dies
Article.where( name: "Frustrated" ).select("CAST (id AS CHAR) ")
even though the SQL looks identical.
Is it possible to do this, what am I doing wrong?
Upvotes: 1
Views: 12217
Reputation: 3499
It was only spaces in the wrong place. This works
Article.where( name: "Frustrated" ).select("CAST(id AS CHAR)")
Upvotes: 5