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
This commit is contained in:
parent
06d49768bd
commit
3df7266056
|
@ -70,9 +70,9 @@ class DatabaseFeatures(BaseDatabaseFeatures):
|
|||
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 @@ class DatabaseWrapper(BaseDatabaseWrapper):
|
|||
'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):
|
||||
|
|
|
@ -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':
|
||||
|
|
|
@ -40,9 +40,9 @@ class DatabaseOperations(PostgresqlDatabaseOperations):
|
|||
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 @@ class DatabaseWrapper(BaseDatabaseWrapper):
|
|||
'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):
|
||||
|
|
Loading…
Reference in New Issue