pythondjangodatabasepostgresql

Case-insensitive search on a postgres ArrayField with django


In the Django documentation for ArrayField, it lists a contains field lookup. However, no icontains (case insensitive lookup - many other fields have it) lookup is present in ArrayField.

I need a case-insensitive lookup function for ArrayField, similar to the pre-existing contains lookup.


Solution

  • icontains, iexact are only applied on string type:

    my_array_field__contains=['H'] 
    

    check if ['H'] is included in my_array_field

    But if you try the following, it will works:

    my_array_field__0__icontains='H'
    

    because it check if the first element contains H or h