Ticket #6523: 6523.diff

File 6523.diff, 1.5 KB (added by Dan Watson, 16 years ago)

text matching for non-text fields in PostgreSQL 8.3

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

     
    3535    def deferrable_sql(self):
    3636        return " DEFERRABLE INITIALLY DEFERRED"
    3737
     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"
     43
    3844    def field_cast_sql(self, db_type):
    3945        if db_type == 'inet':
    4046            return 'HOST(%s)'
  • tests/modeltests/lookup/models.py

     
    3434>>> a7 = Article(headline='Article 7', pub_date=datetime(2005, 7, 27))
    3535>>> a7.save()
    3636
     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>]
     42
    3743# Each QuerySet gets iterator(), which is a generator that "lazily" returns
    3844# results using database-level iteration.
    3945>>> for a in Article.objects.iterator():
Back to Top