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 ? Programmation Python
Les fondamentaux
Voir le programme détaillé
Classe « ValuesBase »

Méthode sqlalchemy.ValuesBase.values

Signature de la méthode values

def values(self, *args: 'Union[_DMLColumnKeyMapping[Any], Sequence[Any]]', **kwargs: 'Any') -> 'Self' 

Description

help(ValuesBase.values)

Specify a fixed VALUES clause for an INSERT statement, or the SET
clause for an UPDATE.

Note that the :class:`_expression.Insert` and
:class:`_expression.Update`
constructs support
per-execution time formatting of the VALUES and/or SET clauses,
based on the arguments passed to :meth:`_engine.Connection.execute`.
However, the :meth:`.ValuesBase.values` method can be used to "fix" a
particular set of parameters into the statement.

Multiple calls to :meth:`.ValuesBase.values` will produce a new
construct, each one with the parameter list modified to include
the new parameters sent.  In the typical case of a single
dictionary of parameters, the newly passed keys will replace
the same keys in the previous construct.  In the case of a list-based
"multiple values" construct, each new list of values is extended
onto the existing list of values.

:param \**kwargs: key value pairs representing the string key
  of a :class:`_schema.Column`
  mapped to the value to be rendered into the
  VALUES or SET clause::

        users.insert().values(name="some name")

        users.update().where(users.c.id == 5).values(name="some name")

:param \*args: As an alternative to passing key/value parameters,
 a dictionary, tuple, or list of dictionaries or tuples can be passed
 as a single positional argument in order to form the VALUES or
 SET clause of the statement.  The forms that are accepted vary
 based on whether this is an :class:`_expression.Insert` or an
 :class:`_expression.Update` construct.

 For either an :class:`_expression.Insert` or
 :class:`_expression.Update`
 construct, a single dictionary can be passed, which works the same as
 that of the kwargs form::

    users.insert().values({"name": "some name"})

    users.update().values({"name": "some new name"})

 Also for either form but more typically for the
 :class:`_expression.Insert` construct, a tuple that contains an
 entry for every column in the table is also accepted::

    users.insert().values((5, "some name"))

 The :class:`_expression.Insert` construct also supports being
 passed a list of dictionaries or full-table-tuples, which on the
 server will render the less common SQL syntax of "multiple values" -
 this syntax is supported on backends such as SQLite, PostgreSQL,
 MySQL, but not necessarily others::

    users.insert().values(
        [
            {"name": "some name"},
            {"name": "some other name"},
            {"name": "yet another name"},
        ]
    )

 The above form would render a multiple VALUES statement similar to:

 .. sourcecode:: sql

        INSERT INTO users (name) VALUES
                        (:name_1),
                        (:name_2),
                        (:name_3)

 It is essential to note that **passing multiple values is
 NOT the same as using traditional executemany() form**.  The above
 syntax is a **special** syntax not typically used.  To emit an
 INSERT statement against multiple rows, the normal method is
 to pass a multiple values list to the
 :meth:`_engine.Connection.execute`
 method, which is supported by all database backends and is generally
 more efficient for a very large number of parameters.

   .. seealso::

       :ref:`tutorial_multiple_parameters` - an introduction to
       the traditional Core method of multiple parameter set
       invocation for INSERTs and other statements.

  The UPDATE construct also supports rendering the SET parameters
  in a specific order.  For this feature refer to the
  :meth:`_expression.Update.ordered_values` method.

   .. seealso::

      :meth:`_expression.Update.ordered_values`




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é