【发布时间】:2014-10-09 05:17:16
【问题描述】:
我需要根据某列中存在多少个单词来过滤记录。
以下工作,但当然返回字符数...我需要一个字数
Flight.where("length(route) > 3")
有没有一种 Rails 方式(或任何方式)可以做到这一点?
这越来越近了(它就在 Rails 文档之外)但会导致错误
Flight.where("array_length(route, 1) >= 3")
ERROR: aggregate functions are not allowed in WHERE
ERROR: function array_length(character varying, integer) does not exist
文档还建议使用 HAVING .. 也不起作用
Flight.having("route.count > ?", 2)
【问题讨论】:
标签: postgresql ruby-on-rails-4