Participer au site avec un Tip
Rechercher
 

Améliorations / Corrections

Vous avez des améliorations (ou des corrections) à proposer pour ce document : je vous remerçie par avance de m'en faire part, cela m'aide à améliorer le site.

Emplacement :

Description des améliorations :

Vous êtes un professionnel et vous avez besoin d'une formation ? Mise en oeuvre d'IHM
avec Qt et PySide6
Voir le programme détaillé
Classe « ColumnOperators »

Méthode sqlalchemy.ColumnOperators.startswith

Signature de la méthode startswith

def startswith(self, other: 'Any', escape: 'Optional[str]' = None, autoescape: 'bool' = False) -> 'ColumnOperators' 

Description

help(ColumnOperators.startswith)

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.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.

:param 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.

:param 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:

  .. sourcecode:: sql

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

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

:param 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:

  .. sourcecode:: sql

    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.

.. seealso::

    :meth:`.ColumnOperators.endswith`

    :meth:`.ColumnOperators.contains`

    :meth:`.ColumnOperators.like`



Vous êtes un professionnel et vous avez besoin d'une formation ? Machine Learning
avec Scikit-Learn
Voir le programme détaillé