I am quite new to django and JSONB and I use this following syntax to execute a search on JSONB data fields:
obj=SomeModel.objects.filter(data__0__fieldX__contains=search_term)
.. and it works as intended. Now, I print out the obj.query for the above statement and I get:
SELECT * FROM "somemodel_some_model"
WHERE ("somemodel_some_model"."data"
#> ['0', 'fieldX']) @> '"some lane"'
However, when I excecute the above using:
obj=SomeModel.objects.raw(`query statement above`)
I get an error:
django.db.utils.ProgrammingError: syntax error at or near "["
LINE 3: #> ['0', 'fieldX']) @> '"some lane"'
I presume I am not escaping the "[", and I have tried using a backslash before, but it does not seem to help.