Opened 9 years ago

Closed 9 years ago

#25538 closed Cleanup/optimization (duplicate)

Clarify the operator that icontains uses on Postgresql

Reported by: Artyem Klimenko Owned by: nobody
Component: Documentation Version: 1.8
Severity: Normal Keywords: postgresql icontains ilike
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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.

Change History (1)

comment:1 by Tim Graham, 9 years ago

Resolution: duplicate
Status: newclosed
Summary: icontains and PostgresqlClarify the operator that icontains uses on Postgresql

Duplicate of #20775

Note: See TracTickets for help on using tickets.
Back to Top