MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / icontains

Method icontains

lib/sqlalchemy/sql/operators.py:1708–1787  ·  view source on GitHub ↗

r"""Implement the ``icontains`` operator, e.g. case insensitive version of :meth:`.ColumnOperators.contains`. Produces a LIKE expression that tests against an insensitive match for the middle of a string value: .. sourcecode:: sql lower(column) LIKE '%'

(self, other: Any, **kw: Any)

Source from the content-addressed store, hash-verified

1706 return self.operate(contains_op, other, **kw)
1707
1708 def icontains(self, other: Any, **kw: Any) -> ColumnOperators:
1709 r"""Implement the ``icontains`` operator, e.g. case insensitive
1710 version of :meth:`.ColumnOperators.contains`.
1711
1712 Produces a LIKE expression that tests against an insensitive match
1713 for the middle of a string value:
1714
1715 .. sourcecode:: sql
1716
1717 lower(column) LIKE '%' || lower(<other>) || '%'
1718
1719 E.g.::
1720
1721 stmt = select(sometable).where(sometable.c.column.icontains("foobar"))
1722
1723 Since the operator uses ``LIKE``, wildcard characters
1724 ``"%"`` and ``"_"`` that are present inside the <other> expression
1725 will behave like wildcards as well. For literal string
1726 values, the :paramref:`.ColumnOperators.icontains.autoescape` flag
1727 may be set to ``True`` to apply escaping to occurrences of these
1728 characters within the string value so that they match as themselves
1729 and not as wildcard characters. Alternatively, the
1730 :paramref:`.ColumnOperators.icontains.escape` parameter will establish
1731 a given character as an escape character which can be of use when
1732 the target expression is not a literal string.
1733
1734 :param other: expression to be compared. This is usually a plain
1735 string value, but can also be an arbitrary SQL expression. LIKE
1736 wildcard characters ``%`` and ``_`` are not escaped by default unless
1737 the :paramref:`.ColumnOperators.icontains.autoescape` flag is
1738 set to True.
1739
1740 :param autoescape: boolean; when True, establishes an escape character
1741 within the LIKE expression, then applies it to all occurrences of
1742 ``"%"``, ``"_"`` and the escape character itself within the
1743 comparison value, which is assumed to be a literal string and not a
1744 SQL expression.
1745
1746 An expression such as::
1747
1748 somecolumn.icontains("foo%bar", autoescape=True)
1749
1750 Will render as:
1751
1752 .. sourcecode:: sql
1753
1754 lower(somecolumn) LIKE '%' || lower(:param) || '%' ESCAPE '/'
1755
1756 With the value of ``:param`` as ``"foo/%bar"``.
1757
1758 :param escape: a character which when given will render with the
1759 ``ESCAPE`` keyword to establish that character as the escape
1760 character. This character can then be placed preceding occurrences
1761 of ``%`` and ``_`` to allow them to act as themselves and not
1762 wildcard characters.
1763
1764 An expression such as::
1765

Calls 1

operateMethod · 0.95