MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / between

Function between

lib/sqlalchemy/sql/_elements_constructors.py:395–454  ·  view source on GitHub ↗

Produce a ``BETWEEN`` predicate clause. E.g.:: from sqlalchemy import between stmt = select(users_table).where(between(users_table.c.id, 5, 7)) Would produce SQL resembling: .. sourcecode:: sql SELECT id, name FROM user WHERE id BETWEEN :id_1 AND :id_2

(
    expr: _ColumnExpressionOrLiteralArgument[_T],
    lower_bound: Any,
    upper_bound: Any,
    symmetric: bool = False,
)

Source from the content-addressed store, hash-verified

393
394
395def between(
396 expr: _ColumnExpressionOrLiteralArgument[_T],
397 lower_bound: Any,
398 upper_bound: Any,
399 symmetric: bool = False,
400) -> BinaryExpression[bool]:
401 """Produce a ``BETWEEN`` predicate clause.
402
403 E.g.::
404
405 from sqlalchemy import between
406
407 stmt = select(users_table).where(between(users_table.c.id, 5, 7))
408
409 Would produce SQL resembling:
410
411 .. sourcecode:: sql
412
413 SELECT id, name FROM user WHERE id BETWEEN :id_1 AND :id_2
414
415 The :func:`.between` function is a standalone version of the
416 :meth:`_expression.ColumnElement.between` method available on all
417 SQL expressions, as in::
418
419 stmt = select(users_table).where(users_table.c.id.between(5, 7))
420
421 All arguments passed to :func:`.between`, including the left side
422 column expression, are coerced from Python scalar values if a
423 the value is not a :class:`_expression.ColumnElement` subclass.
424 For example,
425 three fixed values can be compared as in::
426
427 print(between(5, 3, 7))
428
429 Which would produce::
430
431 :param_1 BETWEEN :param_2 AND :param_3
432
433 :param expr: a column expression, typically a
434 :class:`_expression.ColumnElement`
435 instance or alternatively a Python scalar expression to be coerced
436 into a column expression, serving as the left side of the ``BETWEEN``
437 expression.
438
439 :param lower_bound: a column or Python scalar expression serving as the
440 lower bound of the right side of the ``BETWEEN`` expression.
441
442 :param upper_bound: a column or Python scalar expression serving as the
443 upper bound of the right side of the ``BETWEEN`` expression.
444
445 :param symmetric: if True, will render " BETWEEN SYMMETRIC ". Note
446 that not all databases support this syntax.
447
448 .. seealso::
449
450 :meth:`_expression.ColumnElement.between`
451
452 """

Callers 4

test_between_5Method · 0.90
test_between_6Method · 0.90
test_clausesMethod · 0.90

Calls 1

betweenMethod · 0.45

Tested by 4

test_between_5Method · 0.72
test_between_6Method · 0.72
test_clausesMethod · 0.72