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 ? RAG (Retrieval-Augmented Generation)
et Fine Tuning d'un LLM
Voir le programme détaillé
Classe « Session »

Méthode sqlalchemy.orm.Session.bulk_save_objects

Signature de la méthode bulk_save_objects

def bulk_save_objects(self, objects: 'Iterable[object]', return_defaults: 'bool' = False, update_changed_only: 'bool' = True, preserve_order: 'bool' = True) -> 'None' 

Description

help(Session.bulk_save_objects)

Perform a bulk save of the given list of objects.

.. legacy::

    This method is a legacy feature as of the 2.0 series of
    SQLAlchemy.   For modern bulk INSERT and UPDATE, see
    the sections :ref:`orm_queryguide_bulk_insert` and
    :ref:`orm_queryguide_bulk_update`.

    For general INSERT and UPDATE of existing ORM mapped objects,
    prefer standard :term:`unit of work` data management patterns,
    introduced in the :ref:`unified_tutorial` at
    :ref:`tutorial_orm_data_manipulation`.  SQLAlchemy 2.0
    now uses :ref:`engine_insertmanyvalues` with modern dialects
    which solves previous issues of bulk INSERT slowness.

:param objects: a sequence of mapped object instances.  The mapped
 objects are persisted as is, and are **not** associated with the
 :class:`.Session` afterwards.

 For each object, whether the object is sent as an INSERT or an
 UPDATE is dependent on the same rules used by the :class:`.Session`
 in traditional operation; if the object has the
 :attr:`.InstanceState.key`
 attribute set, then the object is assumed to be "detached" and
 will result in an UPDATE.  Otherwise, an INSERT is used.

 In the case of an UPDATE, statements are grouped based on which
 attributes have changed, and are thus to be the subject of each
 SET clause.  If ``update_changed_only`` is False, then all
 attributes present within each object are applied to the UPDATE
 statement, which may help in allowing the statements to be grouped
 together into a larger executemany(), and will also reduce the
 overhead of checking history on attributes.

:param return_defaults: when True, rows that are missing values which
 generate defaults, namely integer primary key defaults and sequences,
 will be inserted **one at a time**, so that the primary key value
 is available.  In particular this will allow joined-inheritance
 and other multi-table mappings to insert correctly without the need
 to provide primary key values ahead of time; however,
 :paramref:`.Session.bulk_save_objects.return_defaults` **greatly
 reduces the performance gains** of the method overall.  It is strongly
 advised to please use the standard :meth:`_orm.Session.add_all`
 approach.

:param update_changed_only: when True, UPDATE statements are rendered
 based on those attributes in each state that have logged changes.
 When False, all attributes present are rendered into the SET clause
 with the exception of primary key attributes.

:param preserve_order: when True, the order of inserts and updates
 matches exactly the order in which the objects are given.   When
 False, common types of objects are grouped into inserts
 and updates, to allow for more batching opportunities.

.. seealso::

    :doc:`queryguide/dml`

    :meth:`.Session.bulk_insert_mappings`

    :meth:`.Session.bulk_update_mappings`



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