r"""Implement the ``istartswith`` operator, e.g. case insensitive version of :meth:`.ColumnOperators.startswith`. Produces a LIKE expression that tests against an insensitive match for the start of a string value: .. sourcecode:: sql lower(column) LIKE
(
self,
other: Any,
escape: Optional[str] = None,
autoescape: bool = False,
)
| 1166 | ) |
| 1167 | |
| 1168 | def istartswith( |
| 1169 | self, |
| 1170 | other: Any, |
| 1171 | escape: Optional[str] = None, |
| 1172 | autoescape: bool = False, |
| 1173 | ) -> ColumnOperators: |
| 1174 | r"""Implement the ``istartswith`` operator, e.g. case insensitive |
| 1175 | version of :meth:`.ColumnOperators.startswith`. |
| 1176 | |
| 1177 | Produces a LIKE expression that tests against an insensitive |
| 1178 | match for the start of a string value: |
| 1179 | |
| 1180 | .. sourcecode:: sql |
| 1181 | |
| 1182 | lower(column) LIKE lower(<other>) || '%' |
| 1183 | |
| 1184 | E.g.:: |
| 1185 | |
| 1186 | stmt = select(sometable).where(sometable.c.column.istartswith("foobar")) |
| 1187 | |
| 1188 | Since the operator uses ``LIKE``, wildcard characters |
| 1189 | ``"%"`` and ``"_"`` that are present inside the <other> expression |
| 1190 | will behave like wildcards as well. For literal string |
| 1191 | values, the :paramref:`.ColumnOperators.istartswith.autoescape` flag |
| 1192 | may be set to ``True`` to apply escaping to occurrences of these |
| 1193 | characters within the string value so that they match as themselves |
| 1194 | and not as wildcard characters. Alternatively, the |
| 1195 | :paramref:`.ColumnOperators.istartswith.escape` parameter will |
| 1196 | establish a given character as an escape character which can be of |
| 1197 | use when the target expression is not a literal string. |
| 1198 | |
| 1199 | :param other: expression to be compared. This is usually a plain |
| 1200 | string value, but can also be an arbitrary SQL expression. LIKE |
| 1201 | wildcard characters ``%`` and ``_`` are not escaped by default unless |
| 1202 | the :paramref:`.ColumnOperators.istartswith.autoescape` flag is |
| 1203 | set to True. |
| 1204 | |
| 1205 | :param autoescape: boolean; when True, establishes an escape character |
| 1206 | within the LIKE expression, then applies it to all occurrences of |
| 1207 | ``"%"``, ``"_"`` and the escape character itself within the |
| 1208 | comparison value, which is assumed to be a literal string and not a |
| 1209 | SQL expression. |
| 1210 | |
| 1211 | An expression such as:: |
| 1212 | |
| 1213 | somecolumn.istartswith("foo%bar", autoescape=True) |
| 1214 | |
| 1215 | Will render as: |
| 1216 | |
| 1217 | .. sourcecode:: sql |
| 1218 | |
| 1219 | lower(somecolumn) LIKE lower(:param) || '%' ESCAPE '/' |
| 1220 | |
| 1221 | With the value of ``:param`` as ``"foo/%bar"``. |
| 1222 | |
| 1223 | :param escape: a character which when given will render with the |
| 1224 | ``ESCAPE`` keyword to establish that character as the escape |
| 1225 | character. This character can then be placed preceding occurrences |