summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2007-05-23 15:20:25 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2007-05-23 15:20:25 +0000
commit2b2e27d8862637335a5306aea34174c5cf3904bc (patch)
treec2c9e5363132c31eae50b27f721288eeb0458a1c
parentb9e6706e68f13729091011c98edf7e59a697e498 (diff)
downloadsqlalchemy-2b2e27d8862637335a5306aea34174c5cf3904bc.tar.gz
CompoundSelect (i.e. UNION etc.) needed self_group() to provide parenthesis
-rw-r--r--lib/sqlalchemy/sql.py3
-rw-r--r--test/sql/select.py10
2 files changed, 13 insertions, 0 deletions
diff --git a/lib/sqlalchemy/sql.py b/lib/sqlalchemy/sql.py
index 9a93474dc..4304d1ecc 100644
--- a/lib/sqlalchemy/sql.py
+++ b/lib/sqlalchemy/sql.py
@@ -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
diff --git a/test/sql/select.py b/test/sql/select.py
index 281a0f6a3..2f627ee8f 100644
--- a/test/sql/select.py
+++ b/test/sql/select.py
@@ -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(