MCPcopy Create free account
hub / github.com/zzzeek/sqlalchemy / istartswith

Method istartswith

lib/sqlalchemy/sql/operators.py:1358–1443  ·  view source on GitHub ↗

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,
    )

Source from the content-addressed store, hash-verified

1356 )
1357
1358 def istartswith(
1359 self,
1360 other: Any,
1361 escape: Optional[str] = None,
1362 autoescape: bool = False,
1363 ) -> ColumnOperators:
1364 r"""Implement the ``istartswith`` operator, e.g. case insensitive
1365 version of :meth:`.ColumnOperators.startswith`.
1366
1367 Produces a LIKE expression that tests against an insensitive
1368 match for the start of a string value:
1369
1370 .. sourcecode:: sql
1371
1372 lower(column) LIKE lower(<other>) || '%'
1373
1374 E.g.::
1375
1376 stmt = select(sometable).where(sometable.c.column.istartswith("foobar"))
1377
1378 Since the operator uses ``LIKE``, wildcard characters
1379 ``"%"`` and ``"_"`` that are present inside the <other> expression
1380 will behave like wildcards as well. For literal string
1381 values, the :paramref:`.ColumnOperators.istartswith.autoescape` flag
1382 may be set to ``True`` to apply escaping to occurrences of these
1383 characters within the string value so that they match as themselves
1384 and not as wildcard characters. Alternatively, the
1385 :paramref:`.ColumnOperators.istartswith.escape` parameter will
1386 establish a given character as an escape character which can be of
1387 use when the target expression is not a literal string.
1388
1389 :param other: expression to be compared. This is usually a plain
1390 string value, but can also be an arbitrary SQL expression. LIKE
1391 wildcard characters ``%`` and ``_`` are not escaped by default unless
1392 the :paramref:`.ColumnOperators.istartswith.autoescape` flag is
1393 set to True.
1394
1395 :param autoescape: boolean; when True, establishes an escape character
1396 within the LIKE expression, then applies it to all occurrences of
1397 ``"%"``, ``"_"`` and the escape character itself within the
1398 comparison value, which is assumed to be a literal string and not a
1399 SQL expression.
1400
1401 An expression such as::
1402
1403 somecolumn.istartswith("foo%bar", autoescape=True)
1404
1405 Will render as:
1406
1407 .. sourcecode:: sql
1408
1409 lower(somecolumn) LIKE lower(:param) || '%' ESCAPE '/'
1410
1411 With the value of ``:param`` as ``"foo/%bar"``.
1412
1413 :param escape: a character which when given will render with the
1414 ``ESCAPE`` keyword to establish that character as the escape
1415 character. This character can then be placed preceding occurrences

Calls 1

operateMethod · 0.95