]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- added standalone distinct() function in addition to column.distinct()
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 21 Jun 2007 17:42:42 +0000 (17:42 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 21 Jun 2007 17:42:42 +0000 (17:42 +0000)
[ticket:558]

CHANGES
lib/sqlalchemy/sql.py
test/sql/select.py

diff --git a/CHANGES b/CHANGES
index 5e3f960d01a214676922287996f6c9716cdbd243..5bf80221a31e3a0ce2db0a77276af4c98c6ab049 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -25,6 +25,8 @@
       to polymorphic mappers that are using a straight "outerjoin"
       clause
 - sql
+    - added standalone distinct() function in addition to column.distinct()
+      [ticket:558]
     - result.last_inserted_ids() should return a list that is identically
       sized to the primary key constraint of the table.  values that were 
       "passively" created and not available via cursor.lastrowid will be None.
index f9ac753fa885ebcc11b78e39b3d6fda15dcb71e5..92b51dd2589b156464cf31a16c5affc7d5054553 100644 (file)
@@ -34,7 +34,7 @@ __all__ = ['AbstractDialect', 'Alias', 'ClauseElement', 'ClauseParameters',
            'Compiled', 'CompoundSelect', 'Executor', 'FromClause', 'Join',
            'Select', 'Selectable', 'TableClause', 'alias', 'and_', 'asc',
            'between_', 'bindparam', 'case', 'cast', 'column', 'delete',
-           'desc', 'except_', 'except_all', 'exists', 'extract', 'func', 'modifier',
+           'desc', 'distinct', 'except_', 'except_all', 'exists', 'extract', 'func', 'modifier',
            'insert', 'intersect', 'intersect_all', 'join', 'literal',
            'literal_column', 'not_', 'null', 'or_', 'outerjoin', 'select',
            'subquery', 'table', 'text', 'union', 'union_all', 'update',]
@@ -375,6 +375,11 @@ def not_(clause):
 
     return clause._negate()
 
+def distinct(expr):
+    """return a ``DISTINCT`` clause."""
+    
+    return _UnaryExpression(expr, operator="DISTINCT")
+
 def between(ctest, cleft, cright):
     """Return a ``BETWEEN`` predicate clause.
 
@@ -749,8 +754,11 @@ class _FunctionGenerator(object):
         return _Function(self.__names[-1], packagenames=self.__names[0:-1], *c, **o)
 
 func = _FunctionGenerator()
+
+# TODO: use UnaryExpression for this instead ?
 modifier = _FunctionGenerator(group=False)
 
+    
 def _compound_select(keyword, *selects, **kwargs):
     return CompoundSelect(keyword, *selects, **kwargs)
 
index 2f627ee8fe4fcd5567ada32b9ea9c6bcdc1540c6..d8b872098a20fa7e8438bd0affff14aa4053c75e 100644 (file)
@@ -244,6 +244,15 @@ sq.myothertable_othername AS sq_myothertable_othername FROM (" + sqstring + ") A
             checkparams = {'myothertable_othername': 'asdf', 'myothertable_othername_1':'foo', 'myothertable_otherid': 9, 'mytable_myid': 12}
         )
 
+    def testdistinct(self):
+        self.runtest(
+            select([table1.c.myid.distinct()]), "SELECT DISTINCT mytable.myid FROM mytable"
+        )
+
+        self.runtest(
+            select([distinct(table1.c.myid)]), "SELECT DISTINCT mytable.myid FROM mytable"
+        )
+        
     def testoperators(self):
         self.runtest(
             table1.select((table1.c.myid != 12) & ~(table1.c.name=='john')),