Edward
Edward

Reputation: 3499

Cast integer to string - rails - mysql

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

Answers (1)

Edward
Edward

Reputation: 3499

It was only spaces in the wrong place. This works

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

Upvotes: 5

Related Questions