]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
CompoundSelect (i.e. UNION etc.) needed self_group() to provide parenthesis
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 23 May 2007 15:20:25 +0000 (15:20 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 23 May 2007 15:20:25 +0000 (15:20 +0000)
lib/sqlalchemy/sql.py
test/sql/select.py

index 9a93474dc7b6d63f3f89e3447c44f14978b1ef6f..4304d1ecc8783cf2d88d005a5f45f7eae341e363 100644 (file)
@@ -2698,6 +2698,9 @@ class CompoundSelect(_SelectBaseMixin, FromClause):
 
     name = property(lambda s:s.keyword + " statement")
 
+    def self_group(self, against=None):
+        return _Grouping(self)
+
     def _locate_oid_column(self):
         return self.selects[0].oid_column
 
index 281a0f6a381f39a991c4a5ffe86d2683201b5c3c..2f627ee8fe4fcd5567ada32b9ea9c6bcdc1540c6 100644 (file)
@@ -821,6 +821,16 @@ myothertable.othername != :myothertable_othername OR EXISTS (select yay from foo
 
         self.runtest(select([table1], ~table1.c.myid.in_(select([table2.c.otherid]))),
         "SELECT mytable.myid, mytable.name, mytable.description FROM mytable WHERE mytable.myid NOT IN (SELECT myothertable.otherid FROM myothertable)")
+
+        self.runtest(select([table1], table1.c.myid.in_(
+            union(
+                  select([table1], table1.c.myid == 5),
+                  select([table1], table1.c.myid == 12),
+            )
+        )), "SELECT mytable.myid, mytable.name, mytable.description FROM mytable \
+WHERE mytable.myid IN (\
+SELECT mytable.myid, mytable.name, mytable.description FROM mytable WHERE mytable.myid = :mytable_myid \
+UNION SELECT mytable.myid, mytable.name, mytable.description FROM mytable WHERE mytable.myid = :mytable_myid_1)")
         
         # test that putting a select in an IN clause does not blow away its ORDER BY clause
         self.runtest(