#25538: icontains and Postgresql
-------------------------------------+-------------------------------------
     Reporter:  aklim007             |      Owner:  nobody
         Type:                       |     Status:  new
  Cleanup/optimization               |
    Component:  Documentation        |    Version:  1.8
     Severity:  Normal               |   Keywords:  postgresql icontains
                                     |  ilike
 Triage Stage:  Unreviewed           |  Has patch:  0
Easy pickings:  0                    |      UI/UX:  0
-------------------------------------+-------------------------------------
 https://docs.djangoproject.com/en/1.8/ref/models/querysets/#icontains
 > SQL equivalent:
 > SELECT ... WHERE headline ILIKE '%Lennon%';
 ilike exist in PostgreSQL, but not used, and it is not obvious.

 {{{
 q = NetworkObject.objects.filter(string_view__icontains='test').only('id')
 print(q.query)
 SELECT "core_networkobject"."id" FROM "core_networkobject" WHERE
 UPPER("core_networkobject"."string_view"::text) LIKE UPPER(%test%)
 }}}

 I understand that you can not correct the behavior icontains, but you can
 clarify this issue in the documentation.

 And maybe add to the documentation this lookup.
 {{{
 from django.db import models
 from django.db.models.lookups import IContains

 class PostgreILike(IContains):
     lookup_name = 'ilike'

     def as_postgresql(self, compiler, connection):
         lhs, lhs_params = self.process_lhs(compiler, connection)
         rhs, rhs_params = self.process_rhs(compiler, connection)
         params = lhs_params + rhs_params
         return '%s ILIKE %s' % (lhs, rhs), params

 models.CharField.register_lookup(PostgreILike)
 models.TextField.register_lookup(PostgreILike)
 }}}

 P.S. Sorry for my poor English.

--
Ticket URL: <https://code.djangoproject.com/ticket/25538>
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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/051.4063998f3f1def4fe3dee8bc7d3db27a%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to