summaryrefslogtreecommitdiff
path: root/django/db/backends/postgresql_psycopg2/operations.py
diff options
context:
space:
mode:
authorRamiro Morales <cramm0@gmail.com>2011-12-22 20:42:40 +0000
committerRamiro Morales <cramm0@gmail.com>2011-12-22 20:42:40 +0000
commit287565779d3ae4d3229ecbb2ff356c79b920e7d0 (patch)
tree0506c13450b672b18bf407e45e3bfc82e90709b6 /django/db/backends/postgresql_psycopg2/operations.py
parent03eb2907d5e3d600964836287e9d3f48ec7ec667 (diff)
downloaddjango-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.py6
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.