1

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?

1 Answer 1

5

It was only spaces in the wrong place. This works

Article.where( name: "Frustrated" ).select("CAST(id AS CHAR)")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.