dbbase.column_types.WriteOnlyColumn.startswith

WriteOnlyColumn.startswith(other, **kwargs)

Implement the startswith operator.

Produces a LIKE expression that tests against a match for the start of a string value:

column LIKE <other> || '%'

E.g.:

stmt = select([sometable]).\
    where(sometable.c.column.startswith("foobar"))

Since the operator uses LIKE, wildcard characters "%" and "_" that are present inside the <other> expression will behave like wildcards as well. For literal string values, the :paramref:`.ColumnOperators.startswith.autoescape` flag may be set to True to apply escaping to occurrences of these characters within the string value so that they match as themselves and not as wildcard characters. Alternatively, the :paramref:`.ColumnOperators.startswith.escape` parameter will establish a given character as an escape character which can be of use when the target expression is not a literal string.

Parameters
  • other – expression to be compared. This is usually a plain string value, but can also be an arbitrary SQL expression. LIKE wildcard characters % and _ are not escaped by default unless the :paramref:`.ColumnOperators.startswith.autoescape` flag is set to True.

  • autoescape

    boolean; when True, establishes an escape character within the LIKE expression, then applies it to all occurrences of "%", "_" and the escape character itself within the comparison value, which is assumed to be a literal string and not a SQL expression.

    An expression such as:

    somecolumn.startswith("foo%bar", autoescape=True)
    

    Will render as:

    somecolumn LIKE :param || '%' ESCAPE '/'
    

    With the value of :param as "foo/%bar".

    New in version 1.2.

    Changed in version 1.2.0: The :paramref:`.ColumnOperators.startswith.autoescape` parameter is now a simple boolean rather than a character; the escape character itself is also escaped, and defaults to a forwards slash, which itself can be customized using the :paramref:`.ColumnOperators.startswith.escape` parameter.

  • escape

    a character which when given will render with the ESCAPE keyword to establish that character as the escape character. This character can then be placed preceding occurrences of % and _ to allow them to act as themselves and not wildcard characters.

    An expression such as:

    somecolumn.startswith("foo/%bar", escape="^")
    

    Will render as:

    somecolumn LIKE :param || '%' ESCAPE '^'
    

    The parameter may also be combined with :paramref:`.ColumnOperators.startswith.autoescape`:

    somecolumn.startswith("foo%bar^bat", escape="^", autoescape=True)
    

    Where above, the given literal parameter will be converted to "foo^%bar^^bat" before being passed to the database.

See also

ColumnOperators.endswith()

ColumnOperators.contains()

ColumnOperators.like()