summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/orm/query.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2011-02-10 14:17:08 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2011-02-10 14:17:08 -0500
commit3f9a343d725eea883aba2145de4cbb7b84f9d08c (patch)
treef55e890195c76543e689c3b939b84df15cd80a3e /lib/sqlalchemy/orm/query.py
parenta6d54d18c1ddac30940affaa940edaad59e5d63f (diff)
downloadsqlalchemy-3f9a343d725eea883aba2145de4cbb7b84f9d08c.tar.gz
- Query.distinct() now accepts column expressions
as *args, interpreted by the Postgresql dialect as DISTINCT ON (<expr>). [ticket:1069] - select.distinct() now accepts column expressions as *args, interpreted by the Postgresql dialect as DISTINCT ON (<expr>). Note this was already available via passing a list to the `distinct` keyword argument to select(). [ticket:1069] - select.prefix_with() accepts multiple expressions (i.e. *expr), 'prefix' keyword argument to select() accepts a list or tuple. - Passing a string to the `distinct` keyword argument of `select()` for the purpose of emitting special MySQL keywords (DISTINCTROW etc.) is deprecated - use `prefix_with()` for this. - put kw arguments to select() in order - restore docs for _SelectBase, renamed from _SelectBaseMixin
Diffstat (limited to 'lib/sqlalchemy/orm/query.py')
-rw-r--r--lib/sqlalchemy/orm/query.py15
1 files changed, 13 insertions, 2 deletions
diff --git a/lib/sqlalchemy/orm/query.py b/lib/sqlalchemy/orm/query.py
index 79b080927..71a6edd31 100644
--- a/lib/sqlalchemy/orm/query.py
+++ b/lib/sqlalchemy/orm/query.py
@@ -1609,12 +1609,23 @@ class Query(object):
self._offset = offset
@_generative(_no_statement_condition)
- def distinct(self):
+ def distinct(self, *criterion):
"""Apply a ``DISTINCT`` to the query and return the newly resulting
``Query``.
+
+ :param \*expr: optional column expressions. When present,
+ the Postgresql dialect will render a ``DISTINCT ON (<expressions>>)``
+ construct.
"""
- self._distinct = True
+ if not criterion:
+ self._distinct = True
+ else:
+ criterion = self._adapt_col_list(criterion)
+ if isinstance(self._distinct, list):
+ self._distinct += criterion
+ else:
+ self._distinct = criterion
def all(self):
"""Return the results represented by this ``Query`` as a list.