I needed to get something from the database in my job. I tried the current query using PSequel and it gave an error.
SELECT * FROM declarations WHERE data->>'some_data' IS NOT NULL;
The way I got the results was through the console with the following:
bundle exec rails console declarations_ids =  Declaration.find_each do |d| declarations_ids << d.id unless d.data['some_data'].nil? end declarations_ids # [3523, 262623, 623623, ...N-1]
Now we can solve the problem raised by that field.