有一个具有以下结构的 JSONB information
字段:
{
"ignore"=>false
}
我想获取
ignore
字段为 true
的所有记录:@user.posts.where("information ->> 'ignore' = TRUE")
此行引发错误:
PG::UndefinedFunction: ERROR: operator does not exist: text = boolean
我在谷歌找不到任何东西。我们到处都在谈论文本含义。但是没有关于 bool 值的内容。
最佳答案
您必须将 information->>'ignore'
的结果转换为 bool 值:
@user.posts.where("(information ->> 'ignore')::boolean = TRUE")
关于ruby-on-rails - PG::UndefinedFunction: 错误: 运算符不存在: text = boolean,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/59009367/