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 ? Deep Learning avec Python
et Keras et Tensorflow
Voir le programme détaillé
Classe « UpdateBase »

Méthode sqlalchemy.UpdateBase.returning

Signature de la méthode returning

def returning(self, *cols: '_ColumnsClauseArgument[Any]', sort_by_parameter_order: 'bool' = False, **_UpdateBase__kw: 'Any') -> 'UpdateBase' 

Description

help(UpdateBase.returning)

Add a :term:`RETURNING` or equivalent clause to this statement.

e.g.:

.. sourcecode:: pycon+sql

    >>> stmt = (
    ...     table.update()
    ...     .where(table.c.data == "value")
    ...     .values(status="X")
    ...     .returning(table.c.server_flag, table.c.updated_timestamp)
    ... )
    >>> print(stmt)
    {printsql}UPDATE some_table SET status=:status
    WHERE some_table.data = :data_1
    RETURNING some_table.server_flag, some_table.updated_timestamp

The method may be invoked multiple times to add new entries to the
list of expressions to be returned.

.. versionadded:: 1.4.0b2 The method may be invoked multiple times to
 add new entries to the list of expressions to be returned.

The given collection of column expressions should be derived from the
table that is the target of the INSERT, UPDATE, or DELETE.  While
:class:`_schema.Column` objects are typical, the elements can also be
expressions:

.. sourcecode:: pycon+sql

    >>> stmt = table.insert().returning(
    ...     (table.c.first_name + " " + table.c.last_name).label("fullname")
    ... )
    >>> print(stmt)
    {printsql}INSERT INTO some_table (first_name, last_name)
    VALUES (:first_name, :last_name)
    RETURNING some_table.first_name || :first_name_1 || some_table.last_name AS fullname

Upon compilation, a RETURNING clause, or database equivalent,
will be rendered within the statement.   For INSERT and UPDATE,
the values are the newly inserted/updated values.  For DELETE,
the values are those of the rows which were deleted.

Upon execution, the values of the columns to be returned are made
available via the result set and can be iterated using
:meth:`_engine.CursorResult.fetchone` and similar.
For DBAPIs which do not
natively support returning values (i.e. cx_oracle), SQLAlchemy will
approximate this behavior at the result level so that a reasonable
amount of behavioral neutrality is provided.

Note that not all databases/DBAPIs
support RETURNING.   For those backends with no support,
an exception is raised upon compilation and/or execution.
For those who do support it, the functionality across backends
varies greatly, including restrictions on executemany()
and other statements which return multiple rows. Please
read the documentation notes for the database in use in
order to determine the availability of RETURNING.

:param \*cols: series of columns, SQL expressions, or whole tables
 entities to be returned.
:param sort_by_parameter_order: for a batch INSERT that is being
 executed against multiple parameter sets, organize the results of
 RETURNING so that the returned rows correspond to the order of
 parameter sets passed in.  This applies only to an :term:`executemany`
 execution for supporting dialects and typically makes use of the
 :term:`insertmanyvalues` feature.

 .. versionadded:: 2.0.10

 .. seealso::

    :ref:`engine_insertmanyvalues_returning_order` - background on
    sorting of RETURNING rows for bulk INSERT (Core level discussion)

    :ref:`orm_queryguide_bulk_insert_returning_ordered` - example of
    use with :ref:`orm_queryguide_bulk_insert` (ORM level discussion)

.. seealso::

  :meth:`.UpdateBase.return_defaults` - an alternative method tailored
  towards efficient fetching of server-side defaults and triggers
  for single-row INSERTs or UPDATEs.

  :ref:`tutorial_insert_returning` - in the :ref:`unified_tutorial`



Vous êtes un professionnel et vous avez besoin d'une formation ? Programmation Python
Les fondamentaux
Voir le programme détaillé