MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / any_

Function any_

lib/sqlalchemy/sql/_elements_constructors.py:252–309  ·  view source on GitHub ↗

Produce an ANY expression. For dialects such as that of PostgreSQL, this operator applies to usage of the :class:`_types.ARRAY` datatype, for that of MySQL, it may apply to a subquery. e.g.:: # renders on PostgreSQL: # '5 = ANY (somearray)' expr = 5 == any_(myt

(expr: _ColumnExpressionArgument[_T])

Source from the content-addressed store, hash-verified

250
251
252def any_(expr: _ColumnExpressionArgument[_T]) -> CollectionAggregate[bool]:
253 """Produce an ANY expression.
254
255 For dialects such as that of PostgreSQL, this operator applies
256 to usage of the :class:`_types.ARRAY` datatype, for that of
257 MySQL, it may apply to a subquery. e.g.::
258
259 # renders on PostgreSQL:
260 # '5 = ANY (somearray)'
261 expr = 5 == any_(mytable.c.somearray)
262
263 # renders on MySQL:
264 # '5 = ANY (SELECT value FROM table)'
265 expr = 5 == any_(select(table.c.value))
266
267 When using a Python sequence with PostgreSQL, wrap it with
268 :func:`_sql.literal` to produce a SQL expression. Whether the sequence
269 can be adapted to an array parameter is DBAPI-specific::
270
271 expr = 5 == any_(literal([1, 2, 3]))
272
273 Comparison to NULL may work using ``None`` or :func:`_sql.null`::
274
275 None == any_(mytable.c.somearray)
276
277 The any_() / all_() operators also feature a special "operand flipping"
278 behavior such that if any_() / all_() are used on the left side of a
279 comparison using a standalone operator such as ``==``, ``!=``, etc.
280 (not including operator methods such as
281 :meth:`_sql.ColumnOperators.is_`) the rendered expression is flipped::
282
283 # would render '5 = ANY (column)`
284 any_(mytable.c.column) == 5
285
286 Or with ``None``, which note will not perform
287 the usual step of rendering "IS" as is normally the case for NULL::
288
289 # would render 'NULL = ANY(somearray)'
290 any_(mytable.c.somearray) == None
291
292 .. versionchanged:: 1.4.26 repaired the use of any_() / all_()
293 comparing to NULL on the right side to be flipped to the left.
294
295 The column-level :meth:`_sql.ColumnElement.any_` method (not to be
296 confused with :class:`_types.ARRAY` level
297 :meth:`_types.ARRAY.Comparator.any`) is shorthand for
298 ``any_(col)``::
299
300 5 = mytable.c.somearray.any_()
301
302 .. seealso::
303
304 :meth:`_sql.ColumnOperators.any_`
305
306 :func:`_expression.all_`
307
308 """
309 return CollectionAggregate._create_any(expr)

Callers 15

AnyAllTestClass · 0.90

Calls 1

_create_anyMethod · 0.80