Commits

Anonymous committed 7006824

Fixed #6523 -- Use the correct cast on field types for PostgreSQL when
searching within a field column (e.g. "like", "contains", etc). Required for
PostgreSQL 8.3. Thanks to Dan Watson for the patch.

  • Participants
  • Parent commits 02a4eb5

Comments (0)

Files changed (2)

File django/db/backends/postgresql/operations.py

     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)'

File tests/modeltests/lookup/models.py

 >>> 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: Article 1>]
+>>> Article.objects.filter(pub_date__startswith='2005')
+[<Article: Article 5>, <Article: Article 6>, <Article: Article 4>, <Article: Article 2>, <Article: Article 3>, <Article: Article 7>, <Article: Article 1>]
+
 # Each QuerySet gets iterator(), which is a generator that "lazily" returns
 # results using database-level iteration.
 >>> for a in Article.objects.iterator():