]> 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:59 +0000 (14:49 -0400)
WHERE clause.  fixes #3212

lib/sqlalchemy/orm/query.py

index a9ed4d4e71b350e120d4fce8738263496b98b3c2..80d4d0cdd876a61918667d66e569eadc41a7737b 100644 (file)
@@ -2574,6 +2574,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
 
         """