MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / Identity

Class Identity

lib/sqlalchemy/sql/schema.py:6070–6223  ·  view source on GitHub ↗

Defines an identity column, i.e. "GENERATED { ALWAYS | BY DEFAULT } AS IDENTITY" syntax. The :class:`.Identity` construct is an inline construct added to the argument list of a :class:`_schema.Column` object:: from sqlalchemy import Identity Table( "foo",

Source from the content-addressed store, hash-verified

6068
6069
6070class Identity(IdentityOptions, FetchedValue, SchemaItem):
6071 """Defines an identity column, i.e. "GENERATED { ALWAYS | BY DEFAULT }
6072 AS IDENTITY" syntax.
6073
6074 The :class:`.Identity` construct is an inline construct added to the
6075 argument list of a :class:`_schema.Column` object::
6076
6077 from sqlalchemy import Identity
6078
6079 Table(
6080 "foo",
6081 metadata_obj,
6082 Column("id", Integer, Identity()),
6083 Column("description", Text),
6084 )
6085
6086 See the linked documentation below for complete details.
6087
6088 .. versionadded:: 1.4
6089
6090 .. seealso::
6091
6092 :ref:`identity_ddl`
6093
6094 """
6095
6096 __visit_name__ = "identity_column"
6097
6098 is_identity = True
6099
6100 def __init__(
6101 self,
6102 always: bool = False,
6103 on_null: Optional[bool] = None,
6104 start: Optional[int] = None,
6105 increment: Optional[int] = None,
6106 minvalue: Optional[int] = None,
6107 maxvalue: Optional[int] = None,
6108 nominvalue: Optional[bool] = None,
6109 nomaxvalue: Optional[bool] = None,
6110 cycle: Optional[bool] = None,
6111 cache: Optional[int] = None,
6112 order: Optional[bool] = None,
6113 ) -> None:
6114 """Construct a GENERATED { ALWAYS | BY DEFAULT } AS IDENTITY DDL
6115 construct to accompany a :class:`_schema.Column`.
6116
6117 See the :class:`.Sequence` documentation for a complete description
6118 of most parameters.
6119
6120 .. note::
6121 MSSQL supports this construct as the preferred alternative to
6122 generate an IDENTITY on a column, but it uses non standard
6123 syntax that only support :paramref:`_schema.Identity.start`
6124 and :paramref:`_schema.Identity.increment`.
6125 All other parameters are ignored.
6126
6127 :param always:

Callers 15

test_create_ddlMethod · 0.90
test_other_optionsMethod · 0.90
test_nullable_kwargMethod · 0.90
test_on_nullMethod · 0.90
fnMethod · 0.90
test_to_metadataMethod · 0.90
goMethod · 0.90

Calls

no outgoing calls

Tested by 15

test_create_ddlMethod · 0.72
test_other_optionsMethod · 0.72
test_nullable_kwargMethod · 0.72
test_on_nullMethod · 0.72
fnMethod · 0.72
test_to_metadataMethod · 0.72
goMethod · 0.72