MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / or_

Function or_

lib/sqlalchemy/sql/_elements_constructors.py:1511–1561  ·  view source on GitHub ↗

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],
)

Source from the content-addressed store, hash-verified

1509
1510
1511def or_( # type: ignore[empty-body]
1512 initial_clause: Union[Literal[False], _ColumnExpressionArgument[bool]],
1513 *clauses: _ColumnExpressionArgument[bool],
1514) -> ColumnElement[bool]:
1515 """Produce a conjunction of expressions joined by ``OR``.
1516
1517 E.g.::
1518
1519 from sqlalchemy import or_
1520
1521 stmt = select(users_table).where(
1522 or_(users_table.c.name == "wendy", users_table.c.name == "jack")
1523 )
1524
1525 The :func:`.or_` conjunction is also available using the
1526 Python ``|`` operator (though note that compound expressions
1527 need to be parenthesized in order to function with Python
1528 operator precedence behavior)::
1529
1530 stmt = select(users_table).where(
1531 (users_table.c.name == "wendy") | (users_table.c.name == "jack")
1532 )
1533
1534 The :func:`.or_` construct must be given at least one positional
1535 argument in order to be valid; a :func:`.or_` construct with no
1536 arguments is ambiguous. To produce an "empty" or dynamically
1537 generated :func:`.or_` expression, from a given list of expressions,
1538 a "default" element of :func:`_sql.false` (or just ``False``) should be
1539 specified::
1540
1541 from sqlalchemy import false
1542
1543 or_criteria = or_(false(), *expressions)
1544
1545 The above expression will compile to SQL as the expression ``false``
1546 or ``0 = 1``, depending on backend, if no other expressions are
1547 present. If expressions are present, then the :func:`_sql.false` value is
1548 ignored as it does not affect the outcome of an OR expression which
1549 has other elements.
1550
1551 .. deprecated:: 1.4 The :func:`.or_` element now requires that at
1552 least one argument is passed; creating the :func:`.or_` construct
1553 with no arguments is deprecated, and will emit a deprecation warning
1554 while continuing to produce a blank SQL string.
1555
1556 .. seealso::
1557
1558 :func:`.and_`
1559
1560 """
1561 ...
1562
1563
1564if not TYPE_CHECKING:

Callers 15

test_sixMethod · 0.90
test_single_bool_fourMethod · 0.90
test_single_bool_fiveMethod · 0.90
test_single_bool_sixMethod · 0.90
test_single_bool_tenMethod · 0.90
test_fourMethod · 0.90
test_sixMethod · 0.90
test_six_pt_fiveMethod · 0.90
test_eightMethod · 0.90

Calls 1

or_Method · 0.80

Tested by 15

test_sixMethod · 0.72
test_single_bool_fourMethod · 0.72
test_single_bool_fiveMethod · 0.72
test_single_bool_sixMethod · 0.72
test_single_bool_tenMethod · 0.72
test_fourMethod · 0.72
test_sixMethod · 0.72
test_six_pt_fiveMethod · 0.72
test_eightMethod · 0.72