]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- expr.in_() now accepts a text() construct as the argument.
authorMike Bayer <mike_mp@zzzcomputing.com>
Sat, 8 May 2010 20:25:30 +0000 (16:25 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sat, 8 May 2010 20:25:30 +0000 (16:25 -0400)
Grouping parenthesis are added automatically, i.e. usage
is like `col.in_(text("select id from table"))`.
[ticket:1793]

CHANGES
lib/sqlalchemy/sql/expression.py
test/sql/test_compiler.py

diff --git a/CHANGES b/CHANGES
index e2d3303b1f89749a0342441cc59e2399f116a6c4..39326b491f4b26e9affef5745515de9d694c7169 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -13,6 +13,11 @@ CHANGES
     instance if that instance is "pending".  [ticket:1789]
 
 - sql
+  - expr.in_() now accepts a text() construct as the argument.
+    Grouping parenthesis are added automatically, i.e. usage
+    is like `col.in_(text("select id from table"))`.
+    [ticket:1793]
+
   - Fixed bug that prevented implicit RETURNING from functioning
     properly with composite primary key that contained zeroes.
     [ticket:1778]
index 6dd9d8baf3f7347b05d20b682f2b7da86acb1df7..440c118333b04f0ea9e882b2ee857db55f0bab62 100644 (file)
@@ -1522,9 +1522,10 @@ class _CompareMixin(ColumnOperators):
             # column selectable that does not export itself as a FROM clause
             return self.__compare( op, seq_or_selectable.as_scalar(), negate=negate_op)
 
-        elif isinstance(seq_or_selectable, Selectable):
+        elif isinstance(seq_or_selectable, (Selectable, _TextClause)):
             return self.__compare( op, seq_or_selectable, negate=negate_op)
-
+        
+            
         # Handle non selectable arguments as sequences
         args = []
         for o in seq_or_selectable:
@@ -2358,6 +2359,12 @@ class _TextClause(Executable, ClauseElement):
         else:
             return None
 
+    def self_group(self, against=None):
+        if against is operators.in_op:
+            return _Grouping(self)
+        else:
+            return self
+
     def _copy_internals(self, clone=_clone):
         self.bindparams = dict((b.key, clone(b))
                                for b in self.bindparams.values())
index 9490aef378c2d2baef820aa3e7f0d442725d5aa0..9e85d2c7443884a71c8a7f3f1799095b31e9a82b 100644 (file)
@@ -1589,6 +1589,15 @@ sq.myothertable_othername AS sq_myothertable_othername FROM (" + sqstring + ") A
         self.assert_compile(~table1.c.myid.in_(select([table2.c.otherid])),
         "mytable.myid NOT IN (SELECT myothertable.otherid FROM myothertable)")
 
+        # text
+        self.assert_compile(
+                table1.c.myid.in_(
+                        text("SELECT myothertable.otherid FROM myothertable")
+                    ),
+                    "mytable.myid IN (SELECT myothertable.otherid "
+                    "FROM myothertable)"
+        )
+
         # test empty in clause
         self.assert_compile(table1.c.myid.in_([]),
         "mytable.myid != mytable.myid")