MCPcopy
hub / github.com/django/django / Exists

Class Exists

django/db/models/expressions.py:1887–1911  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1885
1886
1887class Exists(Subquery):
1888 template = "EXISTS(%(subquery)s)"
1889 output_field = fields.BooleanField()
1890 empty_result_set_value = False
1891
1892 def __init__(self, queryset, **kwargs):
1893 super().__init__(queryset, **kwargs)
1894 self.query = self.query.exists()
1895
1896 def select_format(self, compiler, sql, params):
1897 # Wrap EXISTS() with a CASE WHEN expression if a database backend
1898 # (e.g. Oracle) doesn't support boolean expression in SELECT or GROUP
1899 # BY list.
1900 if not compiler.connection.features.supports_boolean_expr_in_select_clause:
1901 sql = "CASE WHEN {} THEN 1 ELSE 0 END".format(sql)
1902 return sql, params
1903
1904 def as_sql(self, compiler, *args, **kwargs):
1905 try:
1906 return super().as_sql(compiler, *args, **kwargs)
1907 except EmptyResultSet:
1908 features = compiler.connection.features
1909 if not features.supports_boolean_expr_in_select_clause:
1910 return "1=0", ()
1911 return compiler.compile(Value(False))
1912
1913
1914@deconstructible(path="django.db.models.OrderBy")

Callers 15

with_permMethod · 0.90
validateMethod · 0.90
validateMethod · 0.90
split_excludeMethod · 0.90
get_fallback_sqlMethod · 0.90
test_exact_existsMethod · 0.90

Calls

no outgoing calls