From 974b1bd0fc40e11fc2886b5a9fc333feeeebf546 Mon Sep 17 00:00:00 2001 From: Federico Caselli Date: Sat, 24 Sep 2022 15:50:26 +0200 Subject: Revert automatic set of sequence start to 1 The :class:`.Sequence` construct restores itself to the DDL behavior it had prior to the 1.4 series, where creating a :class:`.Sequence` with no additional arguments will emit a simple ``CREATE SEQUENCE`` instruction **without** any additional parameters for "start value". For most backends, this is how things worked previously in any case; **however**, for MS SQL Server, the default value on this database is ``-2**63``; to prevent this generally impractical default from taking effect on SQL Server, the :paramref:`.Sequence.start` parameter should be provided. As usage of :class:`.Sequence` is unusual for SQL Server which for many years has standardized on ``IDENTITY``, it is hoped that this change has minimal impact. Fixes: #7211 Change-Id: I1207ea10c8cb1528a1519a0fb3581d9621c27b31 --- lib/sqlalchemy/sql/compiler.py | 2 -- lib/sqlalchemy/sql/schema.py | 11 +++++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) (limited to 'lib/sqlalchemy/sql') diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index efe0ea2b4..5b7238a07 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -5674,8 +5674,6 @@ class DDLCompiler(Compiled): if prefix: text += prefix - if create.element.start is None: - create.element.start = self.dialect.default_sequence_base options = self.get_identity_options(create.element) if options: text += " " + options diff --git a/lib/sqlalchemy/sql/schema.py b/lib/sqlalchemy/sql/schema.py index 5bfbd37c7..5d5f76c75 100644 --- a/lib/sqlalchemy/sql/schema.py +++ b/lib/sqlalchemy/sql/schema.py @@ -3323,7 +3323,7 @@ class Sequence(HasSchemaAttr, IdentityOptions, DefaultGenerator): some_table = Table( 'some_table', metadata, - Column('id', Integer, Sequence('some_table_seq'), + Column('id', Integer, Sequence('some_table_seq', start=1), primary_key=True) ) @@ -3375,9 +3375,16 @@ class Sequence(HasSchemaAttr, IdentityOptions, DefaultGenerator): :param start: the starting index of the sequence. This value is used when the CREATE SEQUENCE command is emitted to the database - as the value of the "START WITH" clause. If ``None``, the + as the value of the "START WITH" clause. If ``None``, the clause is omitted, which on most platforms indicates a starting value of 1. + + .. versionchanged:: 2.0 The :paramref:`.Sequence.start` parameter + is required in order to have DDL emit "START WITH". This is a + reversal of a change made in version 1.4 which would implicitly + render "START WITH 1" if the :paramref:`.Sequence.start` were + not included. See :ref:`change_7211` for more detail. + :param increment: the increment value of the sequence. This value is used when the CREATE SEQUENCE command is emitted to the database as the value of the "INCREMENT BY" clause. If ``None``, -- cgit v1.2.1