JSONb with Ruby on Rails

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;

Captura de ecrã 2018-07-01, às 20.03.20

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?

# [3523, 262623, 623623, ...N-1]

Now we can solve the problem raised by that field.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s