ruby-on-railspostgresqlactiverecordruby-on-rails-6

PG::UndefinedFunction: ERROR: operator does not exist: text = boolean


There is a JSONB information field with this structure:

{
  "ignore"=>false
}

I want to get all records whose ignore field is true:

@user.posts.where("information ->> 'ignore' = TRUE")

This line throws an error:

PG::UndefinedFunction: ERROR:  operator does not exist: text = boolean

And I could not find anything in Google. Everywhere we are talking about textual meanings. But there is nothing about booleans.


Solution

  • You must cast the result of information->>'ignore' to boolean:

    @user.posts.where("(information ->> 'ignore')::boolean = TRUE")