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

Function between

lib/sqlalchemy/sql/_elements_constructors.py:380–439  ·  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

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

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