Provides a surrogate :class:`_schema.Column` that will act as a dedicated insert :term:`sentinel` column, allowing efficient bulk inserts with deterministic RETURNING sorting for tables that don't otherwise have qualifying primary key configurations. Adding this column to a :class:`
(
name: Optional[str] = None,
type_: Optional[_TypeEngineArgument[_T]] = None,
*,
default: Optional[Any] = None,
omit_from_statements: bool = True,
)
| 2703 | |
| 2704 | |
| 2705 | def insert_sentinel( |
| 2706 | name: Optional[str] = None, |
| 2707 | type_: Optional[_TypeEngineArgument[_T]] = None, |
| 2708 | *, |
| 2709 | default: Optional[Any] = None, |
| 2710 | omit_from_statements: bool = True, |
| 2711 | ) -> Column[Any]: |
| 2712 | """Provides a surrogate :class:`_schema.Column` that will act as a |
| 2713 | dedicated insert :term:`sentinel` column, allowing efficient bulk |
| 2714 | inserts with deterministic RETURNING sorting for tables that |
| 2715 | don't otherwise have qualifying primary key configurations. |
| 2716 | |
| 2717 | Adding this column to a :class:`.Table` object requires that a |
| 2718 | corresponding database table actually has this column present, so if adding |
| 2719 | it to an existing model, existing database tables would need to be migrated |
| 2720 | (e.g. using ALTER TABLE or similar) to include this column. |
| 2721 | |
| 2722 | For background on how this object is used, see the section |
| 2723 | :ref:`engine_insertmanyvalues_sentinel_columns` as part of the |
| 2724 | section :ref:`engine_insertmanyvalues`. |
| 2725 | |
| 2726 | The :class:`_schema.Column` returned will be a nullable integer column by |
| 2727 | default and make use of a sentinel-specific default generator used only in |
| 2728 | "insertmanyvalues" operations. |
| 2729 | |
| 2730 | .. seealso:: |
| 2731 | |
| 2732 | :func:`_orm.orm_insert_sentinel` |
| 2733 | |
| 2734 | :paramref:`_schema.Column.insert_sentinel` |
| 2735 | |
| 2736 | :ref:`engine_insertmanyvalues` |
| 2737 | |
| 2738 | :ref:`engine_insertmanyvalues_sentinel_columns` |
| 2739 | |
| 2740 | |
| 2741 | .. versionadded:: 2.0.10 |
| 2742 | |
| 2743 | """ |
| 2744 | return Column( |
| 2745 | name=name, |
| 2746 | type_=type_api.INTEGERTYPE if type_ is None else type_, |
| 2747 | default=( |
| 2748 | default if default is not None else _InsertSentinelColumnDefault() |
| 2749 | ), |
| 2750 | _omit_from_statements=omit_from_statements, |
| 2751 | insert_sentinel=True, |
| 2752 | ) |
| 2753 | |
| 2754 | |
| 2755 | class ForeignKey(DialectKWArgs, SchemaItem): |