diff options
author | Ramiro Morales <cramm0@gmail.com> | 2011-12-22 20:42:40 +0000 |
---|---|---|
committer | Ramiro Morales <cramm0@gmail.com> | 2011-12-22 20:42:40 +0000 |
commit | 287565779d3ae4d3229ecbb2ff356c79b920e7d0 (patch) | |
tree | 0506c13450b672b18bf407e45e3bfc82e90709b6 /django/db/backends/postgresql_psycopg2/operations.py | |
parent | 03eb2907d5e3d600964836287e9d3f48ec7ec667 (diff) | |
download | django-287565779d3ae4d3229ecbb2ff356c79b920e7d0.tar.gz |
Added support for modifying the effect of ``DISTINCT`` clauses so they
only consider some fields (PostgreSQL only).
For this, the ``distinct()`` QuerySet method now accepts an optional
list of model fields names and generates ``DISTINCT ON`` clauses on
these cases. Thanks Jeffrey Gelens and Anssi Kääriäinen for their work.
Fixes #6422.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17244 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/db/backends/postgresql_psycopg2/operations.py')
-rw-r--r-- | django/db/backends/postgresql_psycopg2/operations.py | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/django/db/backends/postgresql_psycopg2/operations.py b/django/db/backends/postgresql_psycopg2/operations.py index acfeeaf7ac..949a05c0b6 100644 --- a/django/db/backends/postgresql_psycopg2/operations.py +++ b/django/db/backends/postgresql_psycopg2/operations.py @@ -179,6 +179,12 @@ class DatabaseOperations(BaseDatabaseOperations): return 63 + def distinct_sql(self, fields): + if fields: + return 'DISTINCT ON (%s)' % ', '.join(fields) + else: + return 'DISTINCT' + def last_executed_query(self, cursor, sql, params): # http://initd.org/psycopg/docs/cursor.html#cursor.query # The query attribute is a Psycopg extension to the DB API 2.0. |