Perform a bulk insert of the given list of mapping dictionaries. .. 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:
(
self,
mapper: _EntityBindKey[Any],
mappings: Iterable[Dict[str, Any]],
return_defaults: bool = False,
render_nulls: bool = False,
)
| 4760 | ) |
| 4761 | |
| 4762 | def bulk_insert_mappings( |
| 4763 | self, |
| 4764 | mapper: _EntityBindKey[Any], |
| 4765 | mappings: Iterable[Dict[str, Any]], |
| 4766 | return_defaults: bool = False, |
| 4767 | render_nulls: bool = False, |
| 4768 | ) -> None: |
| 4769 | """Perform a bulk insert of the given list of mapping dictionaries. |
| 4770 | |
| 4771 | .. legacy:: |
| 4772 | |
| 4773 | This method is a legacy feature as of the 2.0 series of |
| 4774 | SQLAlchemy. For modern bulk INSERT and UPDATE, see |
| 4775 | the sections :ref:`orm_queryguide_bulk_insert` and |
| 4776 | :ref:`orm_queryguide_bulk_update`. The 2.0 API shares |
| 4777 | implementation details with this method and adds new features |
| 4778 | as well. |
| 4779 | |
| 4780 | :param mapper: a mapped class, or the actual :class:`_orm.Mapper` |
| 4781 | object, |
| 4782 | representing the single kind of object represented within the mapping |
| 4783 | list. |
| 4784 | |
| 4785 | :param mappings: a sequence of dictionaries, each one containing the |
| 4786 | state of the mapped row to be inserted, in terms of the attribute |
| 4787 | names on the mapped class. If the mapping refers to multiple tables, |
| 4788 | such as a joined-inheritance mapping, each dictionary must contain all |
| 4789 | keys to be populated into all tables. |
| 4790 | |
| 4791 | :param return_defaults: when True, the INSERT process will be altered |
| 4792 | to ensure that newly generated primary key values will be fetched. |
| 4793 | The rationale for this parameter is typically to enable |
| 4794 | :ref:`Joined Table Inheritance <joined_inheritance>` mappings to |
| 4795 | be bulk inserted. |
| 4796 | |
| 4797 | .. note:: for backends that don't support RETURNING, the |
| 4798 | :paramref:`_orm.Session.bulk_insert_mappings.return_defaults` |
| 4799 | parameter can significantly decrease performance as INSERT |
| 4800 | statements can no longer be batched. See |
| 4801 | :ref:`engine_insertmanyvalues` |
| 4802 | for background on which backends are affected. |
| 4803 | |
| 4804 | :param render_nulls: When True, a value of ``None`` will result |
| 4805 | in a NULL value being included in the INSERT statement, rather |
| 4806 | than the column being omitted from the INSERT. This allows all |
| 4807 | the rows being INSERTed to have the identical set of columns which |
| 4808 | allows the full set of rows to be batched to the DBAPI. Normally, |
| 4809 | each column-set that contains a different combination of NULL values |
| 4810 | than the previous row must omit a different series of columns from |
| 4811 | the rendered INSERT statement, which means it must be emitted as a |
| 4812 | separate statement. By passing this flag, the full set of rows |
| 4813 | are guaranteed to be batchable into one batch; the cost however is |
| 4814 | that server-side defaults which are invoked by an omitted column will |
| 4815 | be skipped, so care must be taken to ensure that these are not |
| 4816 | necessary. |
| 4817 | |
| 4818 | .. warning:: |
| 4819 |