3") 是否有轨道方式(或任何方式-6ren">
gpt4 book ai didi

postgresql - Rails 字符串列中的字数大于?

转载 作者:行者123 更新时间:2023-11-29 11:50:11 25 4
gpt4 key购买 nike

我需要根据特定列中存在的单词数来过滤记录。

下面的工作,但当然返回一个字符数......我需要一个字数

 Flight.where("length(route) > 3")

是否有轨道方式(或任何方式)来做到这一点?

这越来越近了(它就在 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)

最佳答案

Flight.where("array_length(route, 1) >= 3") 确实有效,但列必须设置为数组类型。

有关更多信息,请参阅此帖子 Rails Migration changing column to use Postgres arrays

关于postgresql - Rails 字符串列中的字数大于?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26270828/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com