+- sql:
+ - exists() becomes useable as a standalone selectable, not just in a
+ WHERE clause
- orm:
- a full select() construct can be passed to query.select() (which
worked anyway), but also query.selectfirst(), query.selectone() which
"""return extract(field FROM expr)"""
expr = _BinaryClause(text(field), expr, "FROM")
return func.extract(expr)
+
-def exists(*args, **params):
- params['correlate'] = True
- s = select(*args, **params)
- return _BooleanExpression(_TextClause("EXISTS"), s, None)
+def exists(*args, **kwargs):
+ return _Exists(*args, **kwargs)
def union(*selects, **params):
return _compound_select('UNION', *selects, **params)
return _BooleanExpression(self.left, self.right, self.negate, negate=self.operator, type=self.type)
else:
return super(_BooleanExpression, self)._negate()
+
+class _Exists(_BooleanExpression):
+ def __init__(self, *args, **kwargs):
+ kwargs['correlate'] = True
+ s = select(*args, **kwargs)
+ _BooleanExpression.__init__(self, _TextClause("EXISTS"), s, None)
+ def _hide_froms(self):
+ return self._get_from_objects()
class Join(FromClause):
def __init__(self, left, right, onclause=None, isouter = False):
def testdontovercorrelate(self):
self.runtest(select([table1], from_obj=[table1, table1.select()]), """SELECT mytable.myid, mytable.name, mytable.description FROM mytable, (SELECT mytable.myid AS myid, mytable.name AS name, mytable.description AS description FROM mytable)""")
+
+ def testselectexists(self):
+ self.runtest(exists([table1.c.myid], table1.c.myid==5).select(), "SELECT EXISTS (SELECT mytable.myid AS myid FROM mytable WHERE mytable.myid = :mytable_myid)", params={'mytable_myid':5})
def testwheresubquery(self):
# TODO: this tests that you dont get a "SELECT column" without a FROM but its not working yet.