The issue I'm facing is similar to these tickets:
I have a JsonField in a model
data = JSONField(null=True, blank=True)
It contains this json:
{"name":"Hello"}
My filter is:
models.MyModel.objects.filter(data__name__icontains='el')
I expect the query to return the objects that have json where the "name" contains 'el' (case-insensitive).
Instead, I get this:
ProgrammingError at /url/
function upper(jsonb) does not exist
LINE 1: ... UPPER("my_model"."data"...
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
The SQL that causes the error is
WHERE UPPER(("my_model"."data" -> 'name')::text) LIKE UPPER(%el%)
The working SQL is (note added quotes around LIKE text):
WHERE UPPER(("my_model"."data" -> 'name')::text) LIKE UPPER('%el%')
Is there a fix for this? Am I missing something?
Any help would be appreciated.