summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql/schema.py
diff options
context:
space:
mode:
authorFederico Caselli <cfederico87@gmail.com>2023-02-10 21:37:20 +0100
committerMike Bayer <mike_mp@zzzcomputing.com>2023-02-14 14:45:49 -0500
commit3d00c101be9feb73b87b8ad07ddc5bc14cd94cdb (patch)
tree27c68da1e755359bf6c9703082ba8b90ce9002ef /lib/sqlalchemy/sql/schema.py
parenteb0861e8e69f8ce702301c558e552e1aeb2e9eba (diff)
downloadsqlalchemy-3d00c101be9feb73b87b8ad07ddc5bc14cd94cdb.tar.gz
Add ``Table.autoincrement_column``
Added public property :attr:`_sql.Table.autoincrement_column` that returns the column identified as autoincrementing in the column. Fixes: #9277 Change-Id: If60d6f92e0df94f57d00ff6d89d285c61b02f5a4
Diffstat (limited to 'lib/sqlalchemy/sql/schema.py')
-rw-r--r--lib/sqlalchemy/sql/schema.py26
1 files changed, 24 insertions, 2 deletions
diff --git a/lib/sqlalchemy/sql/schema.py b/lib/sqlalchemy/sql/schema.py
index 976432721..2a713fea6 100644
--- a/lib/sqlalchemy/sql/schema.py
+++ b/lib/sqlalchemy/sql/schema.py
@@ -1001,10 +1001,32 @@ class Table(
pass
@util.ro_non_memoized_property
- def _autoincrement_column(self) -> Optional[Column[Any]]:
+ def _autoincrement_column(self) -> Optional[Column[int]]:
return self.primary_key._autoincrement_column
@property
+ def autoincrement_column(self) -> Optional[Column[int]]:
+ """Returns the :class:`.Column` object which currently represents
+ the "auto increment" column, if any, else returns None.
+
+ This is based on the rules for :class:`.Column` as defined by the
+ :paramref:`.Column.autoincrement` parameter, which generally means the
+ column within a single integer column primary key constraint that is
+ not constrained by a foreign key. If the table does not have such
+ a primary key constraint, then there's no "autoincrement" column.
+ A :class:`.Table` may have only one column defined as the
+ "autoincrement" column.
+
+ .. versionadded:: 2.0.4
+
+ .. seealso::
+
+ :paramref:`.Column.autoincrement`
+
+ """
+ return self._autoincrement_column
+
+ @property
def key(self) -> str:
"""Return the 'key' for this :class:`_schema.Table`.
@@ -4756,7 +4778,7 @@ class PrimaryKeyConstraint(ColumnCollectionConstraint):
return list(self._columns)
@util.ro_memoized_property
- def _autoincrement_column(self) -> Optional[Column[Any]]:
+ def _autoincrement_column(self) -> Optional[Column[int]]:
def _validate_autoinc(col: Column[Any], autoinc_true: bool) -> bool:
if col.type._type_affinity is None or not issubclass(
col.type._type_affinity,