]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- clarify documentation on exists() that it is preferred to be in the
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 24 Sep 2014 18:49:30 +0000 (14:49 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 24 Sep 2014 18:49:30 +0000 (14:49 -0400)
WHERE clause.  fixes #3212

lib/sqlalchemy/orm/query.py

index e6b2bf537dbb588db16f892bd1ab921cdbc596c4..7b2ea7977e4a19a077786c59ddc7a2ecdcc64b43 100644 (file)
@@ -2616,6 +2616,19 @@ class Query(object):
                 SELECT 1 FROM users WHERE users.name = :name_1
             ) AS anon_1
 
+        The EXISTS construct is usually used in the WHERE clause::
+
+            session.query(User.id).filter(q.exists()).scalar()
+
+        Note that some databases such as SQL Server don't allow an
+        EXISTS expression to be present in the columns clause of a
+        SELECT.    To select a simple boolean value based on the exists
+        as a WHERE, use :func:`.literal`::
+
+            from sqlalchemy import literal
+
+            session.query(literal(True)).filter(q.exists()).scalar()
+
         .. versionadded:: 0.8.1
 
         """