See :func:`_sql.exists` for a description of usage.
+ An ``EXISTS`` clase can also be construed from a :func:`_sql.select`
+ instance by calling :meth:`_sql.SelectBase.exists`.
+
"""
_from_objects = []
:ref:`tutorial_exists` - in the :term:`2.0 style` tutorial.
+ :meth:`_sql.SelectBase.exists` - method to transform a ``SELECT`` to an
+ ``EXISTS`` clause.
+
""" # noqa E501
if args and isinstance(args[0], (SelectBase, ScalarSelect)):
s = args[0]
e.element = self._regroup(lambda element: element.select_from(*froms))
return e
- def where(self, clause):
+ def where(self, *clause):
"""Return a new :func:`_expression.exists` construct with the
given expression added to
its WHERE clause, joined to the existing clause via AND, if any.
"""
e = self._clone()
- e.element = self._regroup(lambda element: element.where(clause))
+ e.element = self._regroup(lambda element: element.where(*clause))
return e
"SELECT NOT (NOT (EXISTS (SELECT 1))) AS anon_1",
)
+ self.assert_compile(
+ exists(42)
+ .select_from(table1)
+ .where(table1.c.name == "foo", table1.c.description == "bar"),
+ "EXISTS (SELECT 42 FROM mytable WHERE mytable.name = :name_1 "
+ "AND mytable.description = :description_1)",
+ )
+
def test_exists_method(self):
subq = (
select(func.count(table2.c.otherid))