In django, to query JSONB, I do:
cursor.execute("""\
SELECT * FROM "somemodel_some_model"
WHERE UPPER(("somemodel_some_model"."data"
#>> array[0,'fieldX'])::text[])
LIKE UPPER(% %s %)
""",[my_string])
.. and I get:
IndexError: list index out of range
I know the above cant be true because when I use the ORM to achive this using:
obj=Some_Model.objects.filter(data__0__fieldX__icontains=search_term)
.. I get the results. To investigate this, I drop to SQL and do the following:
SELECT * FROM "somemodel_some_model"
WHERE UPPER(("somemodel_some_model"."data"
#>> array[0, 'fieldX'])::text[])
LIKE UPPER(%my_search_string%)
..but, I get:
django.db.utils.ProgrammingError: syntax error at or near "%"
So, the question is, do I need to escape %? Seems odd