r"""Implement the 'endswith' operator. Produces a LIKE expression that tests against a match for the end of a string value: .. sourcecode:: sql column LIKE '%' || <other> E.g.:: stmt = select(sometable).where(sometable.c.column.endswith("f
(
self,
other: Any,
escape: Optional[str] = None,
autoescape: bool = False,
)
| 1443 | ) |
| 1444 | |
| 1445 | def endswith( |
| 1446 | self, |
| 1447 | other: Any, |
| 1448 | escape: Optional[str] = None, |
| 1449 | autoescape: bool = False, |
| 1450 | ) -> ColumnOperators: |
| 1451 | r"""Implement the 'endswith' operator. |
| 1452 | |
| 1453 | Produces a LIKE expression that tests against a match for the end |
| 1454 | of a string value: |
| 1455 | |
| 1456 | .. sourcecode:: sql |
| 1457 | |
| 1458 | column LIKE '%' || <other> |
| 1459 | |
| 1460 | E.g.:: |
| 1461 | |
| 1462 | stmt = select(sometable).where(sometable.c.column.endswith("foobar")) |
| 1463 | |
| 1464 | Since the operator uses ``LIKE``, wildcard characters |
| 1465 | ``"%"`` and ``"_"`` that are present inside the <other> expression |
| 1466 | will behave like wildcards as well. For literal string |
| 1467 | values, the :paramref:`.ColumnOperators.endswith.autoescape` flag |
| 1468 | may be set to ``True`` to apply escaping to occurrences of these |
| 1469 | characters within the string value so that they match as themselves |
| 1470 | and not as wildcard characters. Alternatively, the |
| 1471 | :paramref:`.ColumnOperators.endswith.escape` parameter will establish |
| 1472 | a given character as an escape character which can be of use when |
| 1473 | the target expression is not a literal string. |
| 1474 | |
| 1475 | :param other: expression to be compared. This is usually a plain |
| 1476 | string value, but can also be an arbitrary SQL expression. LIKE |
| 1477 | wildcard characters ``%`` and ``_`` are not escaped by default unless |
| 1478 | the :paramref:`.ColumnOperators.endswith.autoescape` flag is |
| 1479 | set to True. |
| 1480 | |
| 1481 | :param autoescape: boolean; when True, establishes an escape character |
| 1482 | within the LIKE expression, then applies it to all occurrences of |
| 1483 | ``"%"``, ``"_"`` and the escape character itself within the |
| 1484 | comparison value, which is assumed to be a literal string and not a |
| 1485 | SQL expression. |
| 1486 | |
| 1487 | An expression such as:: |
| 1488 | |
| 1489 | somecolumn.endswith("foo%bar", autoescape=True) |
| 1490 | |
| 1491 | Will render as: |
| 1492 | |
| 1493 | .. sourcecode:: sql |
| 1494 | |
| 1495 | somecolumn LIKE '%' || :param ESCAPE '/' |
| 1496 | |
| 1497 | With the value of ``:param`` as ``"foo/%bar"``. |
| 1498 | |
| 1499 | :param escape: a character which when given will render with the |
| 1500 | ``ESCAPE`` keyword to establish that character as the escape |
| 1501 | character. This character can then be placed preceding occurrences |
| 1502 | of ``%`` and ``_`` to allow them to act as themselves and not |