Produce a conjunction of expressions joined by ``OR``. E.g.:: from sqlalchemy import or_ stmt = select(users_table).where( or_(users_table.c.name == "wendy", users_table.c.name == "jack") ) The :func:`.or_` conjunction is also available using the P
( # type: ignore[empty-body]
initial_clause: Union[Literal[False], _ColumnExpressionArgument[bool]],
*clauses: _ColumnExpressionArgument[bool],
)
| 1410 | |
| 1411 | |
| 1412 | def or_( # type: ignore[empty-body] |
| 1413 | initial_clause: Union[Literal[False], _ColumnExpressionArgument[bool]], |
| 1414 | *clauses: _ColumnExpressionArgument[bool], |
| 1415 | ) -> ColumnElement[bool]: |
| 1416 | """Produce a conjunction of expressions joined by ``OR``. |
| 1417 | |
| 1418 | E.g.:: |
| 1419 | |
| 1420 | from sqlalchemy import or_ |
| 1421 | |
| 1422 | stmt = select(users_table).where( |
| 1423 | or_(users_table.c.name == "wendy", users_table.c.name == "jack") |
| 1424 | ) |
| 1425 | |
| 1426 | The :func:`.or_` conjunction is also available using the |
| 1427 | Python ``|`` operator (though note that compound expressions |
| 1428 | need to be parenthesized in order to function with Python |
| 1429 | operator precedence behavior):: |
| 1430 | |
| 1431 | stmt = select(users_table).where( |
| 1432 | (users_table.c.name == "wendy") | (users_table.c.name == "jack") |
| 1433 | ) |
| 1434 | |
| 1435 | The :func:`.or_` construct must be given at least one positional |
| 1436 | argument in order to be valid; a :func:`.or_` construct with no |
| 1437 | arguments is ambiguous. To produce an "empty" or dynamically |
| 1438 | generated :func:`.or_` expression, from a given list of expressions, |
| 1439 | a "default" element of :func:`_sql.false` (or just ``False``) should be |
| 1440 | specified:: |
| 1441 | |
| 1442 | from sqlalchemy import false |
| 1443 | |
| 1444 | or_criteria = or_(false(), *expressions) |
| 1445 | |
| 1446 | The above expression will compile to SQL as the expression ``false`` |
| 1447 | or ``0 = 1``, depending on backend, if no other expressions are |
| 1448 | present. If expressions are present, then the :func:`_sql.false` value is |
| 1449 | ignored as it does not affect the outcome of an OR expression which |
| 1450 | has other elements. |
| 1451 | |
| 1452 | .. deprecated:: 1.4 The :func:`.or_` element now requires that at |
| 1453 | least one argument is passed; creating the :func:`.or_` construct |
| 1454 | with no arguments is deprecated, and will emit a deprecation warning |
| 1455 | while continuing to produce a blank SQL string. |
| 1456 | |
| 1457 | .. seealso:: |
| 1458 | |
| 1459 | :func:`.and_` |
| 1460 | |
| 1461 | """ |
| 1462 | ... |
| 1463 | |
| 1464 | |
| 1465 | if not TYPE_CHECKING: |