Django

Code

Changeset 8242

Show
Ignore:
Timestamp:
08/08/08 15:09:53 (4 months ago)
Author:
mtredinnick
Message:

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.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/db/backends/postgresql/operations.py

    r7789 r8242  
    3535    def deferrable_sql(self): 
    3636        return " DEFERRABLE INITIALLY DEFERRED" 
     37 
     38    def lookup_cast(self, lookup_type): 
     39        if lookup_type in ('iexact', 'contains', 'icontains', 'startswith', 'istartswith', 
     40                             'endswith', 'iendswith'): 
     41            return "%s::text" 
     42        return "%s" 
    3743 
    3844    def field_cast_sql(self, db_type): 
  • django/trunk/tests/modeltests/lookup/models.py

    r7949 r8242  
    3434>>> a7 = Article(headline='Article 7', pub_date=datetime(2005, 7, 27)) 
    3535>>> a7.save() 
     36 
     37# text matching tests for PostgreSQL 8.3 
     38>>> Article.objects.filter(id__iexact='1') 
     39[<Article: Article 1>] 
     40>>> Article.objects.filter(pub_date__startswith='2005') 
     41[<Article: Article 5>, <Article: Article 6>, <Article: Article 4>, <Article: Article 2>, <Article: Article 3>, <Article: Article 7>, <Article: Article 1>] 
    3642 
    3743# Each QuerySet gets iterator(), which is a generator that "lazily" returns