Author: jacob
Date: 2008-08-25 07:56:06 -0500 (Mon, 25 Aug 2008)
New Revision: 8536
Modified:
django/trunk/django/db/backends/postgresql/base.py
django/trunk/django/db/backends/postgresql/operations.py
django/trunk/django/db/backends/postgresql_psycopg2/base.py
Log:
Fixed #3575: use UPPER() instead ILIKE for postgres case-insensitive
comparisons.
Modified: django/trunk/django/db/backends/postgresql/base.py
===================================================================
--- django/trunk/django/db/backends/postgresql/base.py 2008-08-25 12:31:10 UTC
(rev 8535)
+++ django/trunk/django/db/backends/postgresql/base.py 2008-08-25 12:56:06 UTC
(rev 8536)
@@ -70,9 +70,9 @@
class DatabaseWrapper(BaseDatabaseWrapper):
operators = {
'exact': '= %s',
- 'iexact': 'ILIKE %s',
+ 'iexact': '= UPPER(%s)',
'contains': 'LIKE %s',
- 'icontains': 'ILIKE %s',
+ 'icontains': 'LIKE UPPER(%s)',
'regex': '~ %s',
'iregex': '~* %s',
'gt': '> %s',
@@ -81,8 +81,8 @@
'lte': '<= %s',
'startswith': 'LIKE %s',
'endswith': 'LIKE %s',
- 'istartswith': 'ILIKE %s',
- 'iendswith': 'ILIKE %s',
+ 'istartswith': 'LIKE UPPER(%s)',
+ 'iendswith': 'LIKE UPPER(%s)',
}
def __init__(self, *args, **kwargs):
Modified: django/trunk/django/db/backends/postgresql/operations.py
===================================================================
--- django/trunk/django/db/backends/postgresql/operations.py 2008-08-25
12:31:10 UTC (rev 8535)
+++ django/trunk/django/db/backends/postgresql/operations.py 2008-08-25
12:56:06 UTC (rev 8536)
@@ -36,11 +36,19 @@
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':
return 'HOST(%s)'
Modified: django/trunk/django/db/backends/postgresql_psycopg2/base.py
===================================================================
--- django/trunk/django/db/backends/postgresql_psycopg2/base.py 2008-08-25
12:31:10 UTC (rev 8535)
+++ django/trunk/django/db/backends/postgresql_psycopg2/base.py 2008-08-25
12:56:06 UTC (rev 8536)
@@ -40,9 +40,9 @@
class DatabaseWrapper(BaseDatabaseWrapper):
operators = {
'exact': '= %s',
- 'iexact': 'ILIKE %s',
+ 'iexact': '= UPPER(%s)',
'contains': 'LIKE %s',
- 'icontains': 'ILIKE %s',
+ 'icontains': 'LIKE UPPER(%s)',
'regex': '~ %s',
'iregex': '~* %s',
'gt': '> %s',
@@ -51,8 +51,8 @@
'lte': '<= %s',
'startswith': 'LIKE %s',
'endswith': 'LIKE %s',
- 'istartswith': 'ILIKE %s',
- 'iendswith': 'ILIKE %s',
+ 'istartswith': 'LIKE UPPER(%s)',
+ 'iendswith': 'LIKE UPPER(%s)',
}
def __init__(self, *args, **kwargs):
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---