diff --git a/django/db/backends/postgresql/operations.py b/django/db/backends/postgresql/operations.py index ba6e3235c2..de7b5a9520 100644 --- a/django/db/backends/postgresql/operations.py +++ b/django/db/backends/postgresql/operations.py @@ -35,6 +35,12 @@ class DatabaseOperations(BaseDatabaseOperations): def deferrable_sql(self): 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" + def field_cast_sql(self, db_type): if db_type == 'inet': return 'HOST(%s)' diff --git a/tests/modeltests/lookup/models.py b/tests/modeltests/lookup/models.py index 3261a678d6..1d39e0e22b 100644 --- a/tests/modeltests/lookup/models.py +++ b/tests/modeltests/lookup/models.py @@ -34,6 +34,12 @@ __test__ = {'API_TESTS':r""" >>> a7 = Article(headline='Article 7', pub_date=datetime(2005, 7, 27)) >>> a7.save() +# text matching tests for PostgreSQL 8.3 +>>> Article.objects.filter(id__iexact='1') +[] +>>> Article.objects.filter(pub_date__startswith='2005') +[, , , , , , ] + # Each QuerySet gets iterator(), which is a generator that "lazily" returns # results using database-level iteration. >>> for a in Article.objects.iterator():