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,
)
| 4594 | ) |
| 4595 | |
| 4596 | def bulk_insert_mappings( |
| 4597 | self, |
| 4598 | mapper: _EntityBindKey[Any], |
| 4599 | mappings: Iterable[Dict[str, Any]], |
| 4600 | return_defaults: bool = False, |
| 4601 | render_nulls: bool = False, |
| 4602 | ) -> None: |
| 4603 | """Perform a bulk insert of the given list of mapping dictionaries. |
| 4604 | |
| 4605 | .. legacy:: |
| 4606 | |
| 4607 | This method is a legacy feature as of the 2.0 series of |
| 4608 | SQLAlchemy. For modern bulk INSERT and UPDATE, see |
| 4609 | the sections :ref:`orm_queryguide_bulk_insert` and |
| 4610 | :ref:`orm_queryguide_bulk_update`. The 2.0 API shares |
| 4611 | implementation details with this method and adds new features |
| 4612 | as well. |
| 4613 | |
| 4614 | :param mapper: a mapped class, or the actual :class:`_orm.Mapper` |
| 4615 | object, |
| 4616 | representing the single kind of object represented within the mapping |
| 4617 | list. |
| 4618 | |
| 4619 | :param mappings: a sequence of dictionaries, each one containing the |
| 4620 | state of the mapped row to be inserted, in terms of the attribute |
| 4621 | names on the mapped class. If the mapping refers to multiple tables, |
| 4622 | such as a joined-inheritance mapping, each dictionary must contain all |
| 4623 | keys to be populated into all tables. |
| 4624 | |
| 4625 | :param return_defaults: when True, the INSERT process will be altered |
| 4626 | to ensure that newly generated primary key values will be fetched. |
| 4627 | The rationale for this parameter is typically to enable |
| 4628 | :ref:`Joined Table Inheritance <joined_inheritance>` mappings to |
| 4629 | be bulk inserted. |
| 4630 | |
| 4631 | .. note:: for backends that don't support RETURNING, the |
| 4632 | :paramref:`_orm.Session.bulk_insert_mappings.return_defaults` |
| 4633 | parameter can significantly decrease performance as INSERT |
| 4634 | statements can no longer be batched. See |
| 4635 | :ref:`engine_insertmanyvalues` |
| 4636 | for background on which backends are affected. |
| 4637 | |
| 4638 | :param render_nulls: When True, a value of ``None`` will result |
| 4639 | in a NULL value being included in the INSERT statement, rather |
| 4640 | than the column being omitted from the INSERT. This allows all |
| 4641 | the rows being INSERTed to have the identical set of columns which |
| 4642 | allows the full set of rows to be batched to the DBAPI. Normally, |
| 4643 | each column-set that contains a different combination of NULL values |
| 4644 | than the previous row must omit a different series of columns from |
| 4645 | the rendered INSERT statement, which means it must be emitted as a |
| 4646 | separate statement. By passing this flag, the full set of rows |
| 4647 | are guaranteed to be batchable into one batch; the cost however is |
| 4648 | that server-side defaults which are invoked by an omitted column will |
| 4649 | be skipped, so care must be taken to ensure that these are not |
| 4650 | necessary. |
| 4651 | |
| 4652 | .. warning:: |
| 4653 |