summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2017-09-27 10:14:57 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2017-09-27 15:50:07 -0400
commit3a8a8b9bc581fd0b9b61b386e4b0c9273707aef6 (patch)
tree1dcb230576f2b87249bcaf34bf23b119af7c3b6d /lib/sqlalchemy/sql
parentd00a4f7cab11641acb9a48ba4e941ad56fb128d2 (diff)
downloadsqlalchemy-3a8a8b9bc581fd0b9b61b386e4b0c9273707aef6.tar.gz
Support method form of any_(), all_()
Fixed bug where the recently added :meth:`.ColumnOperators.any_` and :meth:`.ColumnOperators.all_` methods didn't work when called as methods, as opposed to using the standalone functions :func:`~.expression.any_` and :func:`~.expression.all_`. Also added documentation examples for these relatively unintuitive SQL operators. Change-Id: I3e56b463e9fd146a077b9970624f50cba27f9811 Fixes: #4093 (cherry picked from commit 944c662d8add498577d6359251d4b94cd84d4011)
Diffstat (limited to 'lib/sqlalchemy/sql')
-rw-r--r--lib/sqlalchemy/sql/default_comparator.py4
-rw-r--r--lib/sqlalchemy/sql/operators.py32
2 files changed, 35 insertions, 1 deletions
diff --git a/lib/sqlalchemy/sql/default_comparator.py b/lib/sqlalchemy/sql/default_comparator.py
index 7498bbe5d..82e36ef3f 100644
--- a/lib/sqlalchemy/sql/default_comparator.py
+++ b/lib/sqlalchemy/sql/default_comparator.py
@@ -15,7 +15,7 @@ from .elements import BindParameter, True_, False_, BinaryExpression, \
Null, _const_expr, _clause_element_as_expr, \
ClauseList, ColumnElement, TextClause, UnaryExpression, \
collate, _is_literal, _literal_as_text, ClauseElement, and_, or_, \
- Slice, Visitable, _literal_as_binds
+ Slice, Visitable, _literal_as_binds, CollectionAggregate
from .selectable import SelectBase, Alias, Selectable, ScalarSelect
@@ -250,6 +250,8 @@ operator_lookup = {
"json_path_getitem_op": (_binary_operate, ),
"json_getitem_op": (_binary_operate, ),
"concat_op": (_binary_operate,),
+ "any_op": (_scalar, CollectionAggregate._create_any),
+ "all_op": (_scalar, CollectionAggregate._create_all),
"lt": (_boolean_compare, operators.ge),
"le": (_boolean_compare, operators.gt),
"ne": (_boolean_compare, operators.eq),
diff --git a/lib/sqlalchemy/sql/operators.py b/lib/sqlalchemy/sql/operators.py
index d88339299..14273dd55 100644
--- a/lib/sqlalchemy/sql/operators.py
+++ b/lib/sqlalchemy/sql/operators.py
@@ -661,6 +661,22 @@ class ColumnOperators(Operators):
"""Produce a :func:`~.expression.any_` clause against the
parent object.
+ This operator is only appropriate against a scalar subquery
+ object, or for some backends an column expression that is
+ against the ARRAY type, e.g.::
+
+ # postgresql '5 = ANY (somearray)'
+ expr = 5 == mytable.c.somearray.any_()
+
+ # mysql '5 = ANY (SELECT value FROM table)'
+ expr = 5 == select([table.c.value]).as_scalar().any_()
+
+ .. seealso::
+
+ :func:`~.expression.any_` - standalone version
+
+ :func:`~.expression.all_` - ALL operator
+
.. versionadded:: 1.1
"""
@@ -670,6 +686,22 @@ class ColumnOperators(Operators):
"""Produce a :func:`~.expression.all_` clause against the
parent object.
+ This operator is only appropriate against a scalar subquery
+ object, or for some backends an column expression that is
+ against the ARRAY type, e.g.::
+
+ # postgresql '5 = ALL (somearray)'
+ expr = 5 == mytable.c.somearray.all_()
+
+ # mysql '5 = ALL (SELECT value FROM table)'
+ expr = 5 == select([table.c.value]).as_scalar().all_()
+
+ .. seealso::
+
+ :func:`~.expression.all_` - standalone version
+
+ :func:`~.expression.any_` - ANY operator
+
.. versionadded:: 1.1
"""