]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Provide example for exists
authorFederico Caselli <cfederico87@gmail.com>
Sat, 27 Jun 2020 19:46:28 +0000 (21:46 +0200)
committerFederico Caselli <cfederico87@gmail.com>
Sat, 27 Jun 2020 19:47:08 +0000 (21:47 +0200)
Fixes: #5423
Change-Id: I716f8de17c49d7eefbbce5ddd9da203bfc9fe47f

lib/sqlalchemy/sql/selectable.py

index bf6f20436e31ca5623c6eb7217c49ed83d35aec0..59c292a079453f56e07734732e16e2f8af36496e 100644 (file)
@@ -4929,7 +4929,15 @@ class Exists(UnaryExpression):
 
             # use on an existing select()
             s = select([table.c.col1]).where(table.c.col2==5)
-            s = exists(s)
+            s_e = exists(s)
+
+            # an exists is usually used in a where of another select
+            # to produce a WHERE EXISTS (SELECT ... )
+            select([table.c.col1]).where(s_e)
+
+            # but can also be used in a select to produce a
+            # SELECT EXISTS (SELECT ... ) query
+            select([s_e])
 
             # construct a select() at once
             exists(['*'], **select_arguments).where(criterion)