Here are the examples of the python api sqlalchemy.exists taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
1 Examples
0
Example 1
Project: ibis Source File: alchemy.py
def _add_select(self, table_set):
to_select = []
has_select_star = False
for expr in self.select_set:
if isinstance(expr, ir.ValueExpr):
arg = self._translate(expr, named=True)
elif isinstance(expr, ir.TableExpr):
if expr.equals(self.table_set):
cached_table = self.context.get_table(expr)
if cached_table is None:
# the select * case from materialized join
has_select_star = True
continue
else:
arg = table_set
else:
arg = self.context.get_table(expr)
if arg is None:
raise ValueError(expr)
to_select.append(arg)
if has_select_star:
if table_set is None:
raise ValueError('table_set cannot be None here')
clauses = [table_set] + to_select
else:
clauses = to_select
if self.exists:
result = sa.exists(clauses)
else:
result = sa.select(clauses)
if self.distinct:
result = result.distinct()
if not has_select_star:
if table_set is not None:
return result.select_from(table_set)
else:
return result
else:
return result