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.

Comments (0)

Files changed (2)

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

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():
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.