diff options
author | Jacob Kaplan-Moss <jacob@jacobian.org> | 2008-08-25 12:56:06 +0000 |
---|---|---|
committer | Jacob Kaplan-Moss <jacob@jacobian.org> | 2008-08-25 12:56:06 +0000 |
commit | 3df72660560730393fc958700d2a3ab975c4b361 (patch) | |
tree | 9da68ca3094b0d24abe06e1438cb1f18e8c43ada /django/db/backends/postgresql/operations.py | |
parent | 06d49768bd6974a455e6dd46e9526a093721897e (diff) | |
download | django-3df72660560730393fc958700d2a3ab975c4b361.tar.gz |
Fixed #3575: use UPPER() instead ILIKE for postgres case-insensitive comparisons.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@8536 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/db/backends/postgresql/operations.py')
-rw-r--r-- | django/db/backends/postgresql/operations.py | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/django/db/backends/postgresql/operations.py b/django/db/backends/postgresql/operations.py index 4eb5ead47c..01cc1fc8b7 100644 --- a/django/db/backends/postgresql/operations.py +++ b/django/db/backends/postgresql/operations.py @@ -36,10 +36,18 @@ class DatabaseOperations(BaseDatabaseOperations): return " DEFERRABLE INITIALLY DEFERRED" def lookup_cast(self, lookup_type): - if lookup_type in ('iexact', 'contains', 'icontains', 'startswith', 'istartswith', - 'endswith', 'iendswith'): - return "%s::text" - return "%s" + lookup = '%s' + + # Cast text lookups to text to allow things like filter(x__contains=4) + if lookup_type in ('iexact', 'contains', 'icontains', 'startswith', + 'istartswith', 'endswith', 'iendswith'): + lookup = "%s::text" + + # Use UPPER(x) for case-insensitive lookups; it's faster. + if lookup_type in ('iexact', 'icontains', 'istartswith', 'iendswith'): + lookup = 'UPPER(%s)' % lookup + + return lookup def field_cast_sql(self, db_type): if db_type == 'inet': |