ActiveRecord查询。其中字符串为数字

Car*_*ela 1 ruby activerecord ruby-on-rails

我在我的数据库中记录了一个时间元素,它是一个存储为字符串的数字。我想运行一个where查询,检查数字是否大于x,例如

Recording.where("recording_duration_ms.to_i > 60000")
Run Code Online (Sandbox Code Playgroud)

确保一定很简单...

Kal*_*man 5

完善@Alex Peachey给的答案...

为了避免SQL注入,您想使用?hash

Recording.where("CAST(recording_duration_ms AS INT) > ?", 60000)

要么

Recording.where("CAST(recording_duration_ms AS INT) > :duration", duration: 60000)