Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@8242 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 32d5c39016f7f14dfc19142d78d944d92eb9cd70 1 parent 6d4b143
@malcolmt malcolmt authored
View
6 django/db/backends/postgresql/operations.py
@@ -35,6 +35,12 @@ def date_trunc_sql(self, lookup_type, field_name):
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)'
View
6 tests/modeltests/lookup/models.py
@@ -34,6 +34,12 @@ def __unicode__(self):
>>> 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():
Please sign in to comment.
Something went wrong with that request. Please try again.