MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / startswith

Method startswith

lib/sqlalchemy/sql/operators.py:1267–1356  ·  lib/sqlalchemy/sql/operators.py::ColumnOperators.startswith

r"""Implement the ``startswith`` operator. Produces a LIKE expression that tests against a match for the start of a string value: .. sourcecode:: sql column LIKE <other> || '%' E.g.:: stmt = select(sometable).where(sometable.c.column.start

(
        self,
        other: Any,
        escape: Optional[str] = None,
        autoescape: bool = False,
    )

Source from the content-addressed store, hash-verified

1265 isnot = is_not
1266
1267 def startswith(
1268 self,
1269 other: Any,
1270 escape: Optional[str] = None,
1271 autoescape: bool = False,
1272 ) -> ColumnOperators:
1273 rclass="st">"""Implement the ``startswith`` operator.
1274
1275 Produces a LIKE expression that tests against a match for the start
1276 of a string value:
1277
1278 .. sourcecode:: sql
1279
1280 column LIKE <other> || &class="cm">#x27;%'
1281
1282 E.g.::
1283
1284 stmt = select(sometable).where(sometable.c.column.startswith(class="st">"foobar"))
1285
1286 Since the operator uses ``LIKE``, wildcard characters
1287 ``class="st">"%"`` and ``class="st">"_"`` that are present inside the <other> expression
1288 will behave like wildcards as well. For literal string
1289 values, the :paramref:`.ColumnOperators.startswith.autoescape` flag
1290 may be set to ``True`` to apply escaping to occurrences of these
1291 characters within the string value so that they match as themselves
1292 and not as wildcard characters. Alternatively, the
1293 :paramref:`.ColumnOperators.startswith.escape` parameter will establish
1294 a given character as an escape character which can be of use when
1295 the target expression is not a literal string.
1296
1297 :param other: expression to be compared. This is usually a plain
1298 string value, but can also be an arbitrary SQL expression. LIKE
1299 wildcard characters ``%`` and ``_`` are not escaped by default unless
1300 the :paramref:`.ColumnOperators.startswith.autoescape` flag is
1301 set to True.
1302
1303 :param autoescape: boolean; when True, establishes an escape character
1304 within the LIKE expression, then applies it to all occurrences of
1305 ``class="st">"%"``, ``class="st">"_"`` and the escape character itself within the
1306 comparison value, which is assumed to be a literal string and not a
1307 SQL expression.
1308
1309 An expression such as::
1310
1311 somecolumn.startswith(class="st">"foo%bar", autoescape=True)
1312
1313 Will render as:
1314
1315 .. sourcecode:: sql
1316
1317 somecolumn LIKE :param || &class="cm">#x27;%class="st">' ESCAPE '/'
1318
1319 With the value of ``:param`` as ``class="st">"foo/%bar"``.
1320
1321 :param escape: a character which when given will render with the
1322 ``ESCAPE`` keyword to establish that character as the escape
1323 character. This character can then be placed preceding occurrences
1324 of ``%`` and ``_`` to allow them to act as themselves and not

Callers 15

process_functionsFunction · 0.45
process_moduleFunction · 0.45
_recur_paramFunction · 0.45
apply_pytest_optsFunction · 0.45
process_moduleFunction · 0.45
_format_blockFunction · 0.45
format_fileFunction · 0.45
_reflect_typeMethod · 0.45
_load_domainsMethod · 0.45
_execute_reflectionMethod · 0.45

Calls 1

operateMethod · 0.95

Tested by 15

_all_subclassesMethod · 0.36
_apply_maybe_asyncFunction · 0.36
decorateMethod · 0.36
test_startswithMethod · 0.36