PG::UndefinedFunction: 错误: 运算符不存在: text = boolean

Col*_*bri 3 postgresql activerecord ruby-on-rails ruby-on-rails-6

有一个information具有此结构的 JSONB字段:

{
  "ignore"=>false
}
Run Code Online (Sandbox Code Playgroud)

我想获取其ignore字段为的所有记录true

{
  "ignore"=>false
}
Run Code Online (Sandbox Code Playgroud)

此行引发错误:

PG::UndefinedFunction: ERROR:  operator does not exist: text = boolean
Run Code Online (Sandbox Code Playgroud)

我在谷歌找不到任何东西。我们到处都在谈论文本含义。但是没有关于布尔值的内容。

Seb*_*lma 5

您必须将结果转换information->>'ignore'为布尔值:

@user.posts.where("(information ->> 'ignore')::boolean = TRUE")
Run Code Online (Sandbox Code Playgroud)