MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / endswith

Method endswith

lib/sqlalchemy/sql/operators.py:1255–1344  ·  view source on GitHub ↗

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 '%' || E.g.:: stmt = select(sometable).where(sometable.c.column.endswith("f

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

Source from the content-addressed store, hash-verified

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

Callers 15

_testsFunction · 0.45
_reap_oracle_dbsFunction · 0.45
coercions.pyFile · 0.45
__getattr__Method · 0.45
tokenMethod · 0.45
_chop_pathMethod · 0.45
_apply_to_parentMethod · 0.45
test_endswith_sqlexprMethod · 0.45

Calls 1

operateMethod · 0.95