#34942: Add icontains support for PostgreSQL ArrayField
-------------------------------------+-------------------------------------
               Reporter:             |          Owner:  nobody
  aminabbasov                        |
                   Type:  New        |         Status:  new
  feature                            |
              Component:  Database   |        Version:  4.2
  layer (models, ORM)                |       Keywords:  QuerySet.extra,
               Severity:  Normal     |  ArrayField, PostgreSQL, icontains
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 Django ORM for PostgreSQL ArrayField allows to make only "contains", and
 doesn't support "icontains", although the database itself supports this
 type of query.

 For example, I have this Product table:

 {{{#!python
 class Product(models.Model):
     name = models.CharField(max_length=255)
     options = ArrayField(base_field=models.CharField(max_length=255))

     def __str__(self):
         return self.name
 }}}

 And only two rows in table:

 ||= id =||= name =||= options =||
 || 1 || First || ["foo", "Bar", "BAZ"] ||
 || 2 || Second || ["Foo", "Bar", "baZ"] ||

 If I want to filter rows by options сolumn, I can make only this ORM
 queries:

 {{{#!bash
 >>> Product.objects.filter(options__contains: "foo")
 <ProductQuerySet [<Product: First>]>

 >>> Product.objects.filter(options__contains: "Bar")
 <ProductQuerySet [<Product: First>, <Product: Second>]>
 }}}

 But if I want to do case-insensitive filtering,
 {{{Product.objects.filter(options__icontains: "foo")}}} wouldn't work. So,
 the only option to do this query, is to use {{{.extra()}}} method:

 {{{#!bash
 >>> Product.objects.extra(
 ...     where=['%s ILIKE ANY (options)'],
 ...     params=["foo"],
 ...     )
 <ProductQuerySet [<Product: First>, <Product: Second>]>
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/34942>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107018b914aebed-8a87546f-efbe-471b-8342-35885230449e-000000%40eu-central-1.amazonses.com.

Reply via email to