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,
)
| 2980 | |
| 2981 | |
| 2982 | def insert_sentinel( |
| 2983 | name: Optional[str] = None, |
| 2984 | type_: Optional[_TypeEngineArgument[_T]] = None, |
| 2985 | *, |
| 2986 | default: Optional[Any] = None, |
| 2987 | omit_from_statements: bool = True, |
| 2988 | ) -> Column[Any]: |
| 2989 | """Provides a surrogate :class:`_schema.Column` that will act as a |
| 2990 | dedicated insert :term:`sentinel` column, allowing efficient bulk |
| 2991 | inserts with deterministic RETURNING sorting for tables that |
| 2992 | don't otherwise have qualifying primary key configurations. |
| 2993 | |
| 2994 | Adding this column to a :class:`.Table` object requires that a |
| 2995 | corresponding database table actually has this column present, so if adding |
| 2996 | it to an existing model, existing database tables would need to be migrated |
| 2997 | (e.g. using ALTER TABLE or similar) to include this column. |
| 2998 | |
| 2999 | For background on how this object is used, see the section |
| 3000 | :ref:`engine_insertmanyvalues_sentinel_columns` as part of the |
| 3001 | section :ref:`engine_insertmanyvalues`. |
| 3002 | |
| 3003 | The :class:`_schema.Column` returned will be a nullable integer column by |
| 3004 | default and make use of a sentinel-specific default generator used only in |
| 3005 | "insertmanyvalues" operations. |
| 3006 | |
| 3007 | .. seealso:: |
| 3008 | |
| 3009 | :func:`_orm.orm_insert_sentinel` |
| 3010 | |
| 3011 | :paramref:`_schema.Column.insert_sentinel` |
| 3012 | |
| 3013 | :ref:`engine_insertmanyvalues` |
| 3014 | |
| 3015 | :ref:`engine_insertmanyvalues_sentinel_columns` |
| 3016 | |
| 3017 | |
| 3018 | .. versionadded:: 2.0.10 |
| 3019 | |
| 3020 | """ |
| 3021 | return Column( |
| 3022 | name=name, |
| 3023 | type_=type_api.INTEGERTYPE if type_ is None else type_, |
| 3024 | default=( |
| 3025 | default if default is not None else _InsertSentinelColumnDefault() |
| 3026 | ), |
| 3027 | _omit_from_statements=omit_from_statements, |
| 3028 | insert_sentinel=True, |
| 3029 | ) |
| 3030 | |
| 3031 | |
| 3032 | class ForeignKey(DialectKWArgs, SchemaItem): |