From: Mike Bayer Date: Wed, 24 Sep 2014 18:49:30 +0000 (-0400) Subject: - clarify documentation on exists() that it is preferred to be in the X-Git-Tag: rel_0_9_8~17 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=98f457a5e2f8b9ec9f13a575fc99eca2ef1fc310;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - clarify documentation on exists() that it is preferred to be in the WHERE clause. fixes #3212 --- diff --git a/lib/sqlalchemy/orm/query.py b/lib/sqlalchemy/orm/query.py index a9ed4d4e71..80d4d0cdd8 100644 --- a/lib/sqlalchemy/orm/query.py +++ b/lib/sqlalchemy/orm/query.py @@ -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 """