Hi
I recently came across a very interesting scenario. I have a JSON Field which I want to query on. I was trying to do some performance optimizations and came across this
If I query a non-JSON field like this:
Study.objects.all().filter(study_id__in=[Value("Tes1"),Value("Test2")])
and
Study.objects.all().filter(study_id__in=["Test1","Test2"])
both of these queries return the same results
but if I try performing the same on a JSONField
Study.objects.all().filter(study_data__protocol__general__program_name__in=(Value("Program1"), Value("Program2")))
results in
DataError: invalid input syntax for type json
LINE 1: ...> ARRAY['protocol','general','program_name']) IN ('Prog ...
^
DETAIL: Token "Program1" is invalid.
CONTEXT: JSON data, line 1: Program1
and
Study.objects.all().filter(study_data__protocol__general__program_name__in=("Program1","Program2"))
works fine.
I am not sure if this is a potential bug with Django or is like this by design. Would really appreciate if someone can explain this behavior difference.
Cheers