0

Please see an example here: http://edgeguides.rubyonrails.org/active_record_postgresql.html#json

How do I get all the records containing "jack" inside change array?

I can currently do it with such a query:

Event.where("payload #>> '{change,0}' = 'jack' ")

But what if I don't know the exact "jack"'s position (0 in this case) inside change array? How to rearrange the Rails PSQL query then?

prograils
  • 2,248
  • 1
  • 28
  • 45

1 Answers1

0

Take a look at Query for array elements inside JSON type, especially discussion of the @> (contains) operator (if you're using a jsonb column).

Community
  • 1
  • 1
gmcnaughton
  • 2,233
  • 1
  • 21
  • 28