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