From: Jason Kirtland Date: Thu, 9 Aug 2007 18:31:59 +0000 (+0000) Subject: tweak DISTINCT precedence for clauses like `func.count(t.c.col.distinct())` X-Git-Tag: rel_0_3_11~22 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cb9356070dc9d64af4e146db2889d1d3341b9b6c;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git tweak DISTINCT precedence for clauses like `func.count(t.c.col.distinct())` --- diff --git a/CHANGES b/CHANGES index 3e4d174a6e..4a6868df70 100644 --- a/CHANGES +++ b/CHANGES @@ -1,4 +1,7 @@ 0.3.11 +- sql + - tweak DISTINCT precedence for clauses like + `func.count(t.c.col.distinct())` - orm - added a check for joining from A->B using join(), along two different m2m tables. this raises an error in 0.3 but is diff --git a/lib/sqlalchemy/sql.py b/lib/sqlalchemy/sql.py index 8b454947ef..3233aad68f 100644 --- a/lib/sqlalchemy/sql.py +++ b/lib/sqlalchemy/sql.py @@ -63,6 +63,7 @@ PRECEDENCE = { '>=':5, '<=':5, 'BETWEEN':5, + 'DISTINCT':5, 'NOT':4, 'AND':3, 'OR':2, diff --git a/test/sql/select.py b/test/sql/select.py index 4d3eb4ad70..030bf44dce 100644 --- a/test/sql/select.py +++ b/test/sql/select.py @@ -259,6 +259,14 @@ sq.myothertable_othername AS sq_myothertable_othername FROM (" + sqstring + ") A self.runtest( select([distinct(table1.c.myid)]), "SELECT DISTINCT mytable.myid FROM mytable" ) + + self.runtest( + select([func.count(table1.c.myid.distinct())]), "SELECT count(DISTINCT mytable.myid) FROM mytable" + ) + + self.runtest( + select([func.count(distinct(table1.c.myid))]), "SELECT count(DISTINCT mytable.myid) FROM mytable" + ) def testoperators(self): self.runtest(