From 668872fe0108c3885adcf6cb10b653b812dc258f Mon Sep 17 00:00:00 2001 From: Gord Thompson Date: Sun, 19 Apr 2020 11:47:19 -0600 Subject: Add support for "real" sequences in mssql Added support for "CREATE SEQUENCE" and full :class:`.Sequence` support for Microsoft SQL Server. This removes the deprecated feature of using :class:`.Sequence` objects to manipulate IDENTITY characteristics which should now be performed using ``mssql_identity_start`` and ``mssql_identity_increment`` as documented at :ref:`mssql_identity`. The change includes a new parameter :paramref:`.Sequence.data_type` to accommodate SQL Server's choice of datatype, which for that backend includes INTEGER and BIGINT. The default starting value for SQL Server's version of :class:`.Sequence` has been set at 1; this default is now emitted within the CREATE SEQUENCE DDL for all backends. Fixes: #4235 Fixes: #4633 Change-Id: I6aa55c441e8146c2f002e2e201a7f645e667b916 --- lib/sqlalchemy/sql/compiler.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'lib/sqlalchemy/sql/compiler.py') diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index fc66ca517..4bd19e04b 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -3743,14 +3743,17 @@ class DDLCompiler(Compiled): drop.element, use_table=True ) - def visit_create_sequence(self, create, **kw): + def visit_create_sequence(self, create, prefix=None, **kw): text = "CREATE SEQUENCE %s" % self.preparer.format_sequence( create.element ) + if prefix: + text += prefix if create.element.increment is not None: text += " INCREMENT BY %d" % create.element.increment - if create.element.start is not None: - text += " START WITH %d" % create.element.start + if create.element.start is None: + create.element.start = self.dialect.default_sequence_base + text += " START WITH %d" % create.element.start if create.element.minvalue is not None: text += " MINVALUE %d" % create.element.minvalue if create.element.maxvalue is not None: -- cgit v1.2.1