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_1_0_0b1~70^2~66 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=42837f4bca6a0b2fad05faade7837719f872c35d;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 e6b2bf537d..7b2ea7977e 100644 --- a/lib/sqlalchemy/orm/query.py +++ b/lib/sqlalchemy/orm/query.py @@ -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 """