]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- allow exists(s.as_scalar()) to work
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 28 Jan 2010 21:13:38 +0000 (21:13 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 28 Jan 2010 21:13:38 +0000 (21:13 +0000)
lib/sqlalchemy/sql/expression.py
test/sql/test_select.py

index bf3d16e695f252487fe2c251d434efe8bd50a697..5f17c223c5acf68f70063a7f8477f6d3a51ddd7a 100644 (file)
@@ -2680,7 +2680,7 @@ class _Exists(_UnaryExpression):
     _from_objects = []
 
     def __init__(self, *args, **kwargs):
-        if args and isinstance(args[0], _SelectBaseMixin):
+        if args and isinstance(args[0], (_SelectBaseMixin, _ScalarSelect)):
             s = args[0]
         else:
             if not args:
index d5ba8fa9e73fa8a4e534d59bdad9c5f063e847ca..8390c73424c3a5fd2ea323b1884ab49ef24412dd 100644 (file)
@@ -279,6 +279,16 @@ sq.myothertable_othername AS sq_myothertable_othername FROM (" + sqstring + ") A
         self.assert_compile(s, "SELECT t.a WHERE t.a = t2.d")
         
     def test_exists(self):
+        s = select([table1.c.myid]).where(table1.c.myid==5)
+        
+        self.assert_compile(exists(s), 
+                    "EXISTS (SELECT mytable.myid FROM mytable WHERE mytable.myid = :myid_1)"
+                )
+        
+        self.assert_compile(exists(s.as_scalar()), 
+                    "EXISTS (SELECT mytable.myid FROM mytable WHERE mytable.myid = :myid_1)"
+                )
+        
         self.assert_compile(exists([table1.c.myid], table1.c.myid==5).select(), "SELECT EXISTS (SELECT mytable.myid FROM mytable WHERE mytable.myid = :myid_1)", params={'mytable_myid':5})
 
         self.assert_compile(select([table1, exists([1], from_obj=table2)]), "SELECT mytable.myid, mytable.name, mytable.description, EXISTS (SELECT 1 FROM myothertable) FROM mytable", params={})