diff --git a/src/snowflake/sqlalchemy/base.py b/src/snowflake/sqlalchemy/base.py index 2a1bb51a..e008c92f 100644 --- a/src/snowflake/sqlalchemy/base.py +++ b/src/snowflake/sqlalchemy/base.py @@ -966,11 +966,14 @@ def visit_drop_column_comment(self, drop, **kw): ) def visit_identity_column(self, identity, **kw): - text = " IDENTITY" + text = "IDENTITY" if identity.start is not None or identity.increment is not None: start = 1 if identity.start is None else identity.start increment = 1 if identity.increment is None else identity.increment text += f"({start},{increment})" + if identity.order is not None: + order = "ORDER" if identity.order else "NOORDER" + text += f" {order}" return text def get_identity_options(self, identity_options): diff --git a/tests/test_sequence.py b/tests/test_sequence.py index e428b9d7..32fc390e 100644 --- a/tests/test_sequence.py +++ b/tests/test_sequence.py @@ -4,6 +4,7 @@ from sqlalchemy import ( Column, + Identity, Integer, MetaData, Sequence, @@ -13,6 +14,7 @@ select, ) from sqlalchemy.sql import text +from sqlalchemy.sql.ddl import CreateTable def test_table_with_sequence(engine_testaccount, db_parameters): @@ -135,3 +137,27 @@ def test_table_with_autoincrement(engine_testaccount): finally: metadata.drop_all(engine_testaccount) + + +def test_table_with_identity(sql_compiler): + test_table_name = "identity" + metadata = MetaData() + identity_autoincrement_table = Table( + test_table_name, + metadata, + Column( + "id", Integer, Identity(start=1, increment=1, order=True), primary_key=True + ), + Column("identity_col_unordered", Integer, Identity(order=False)), + Column("identity_col", Integer, Identity()), + ) + create_table = CreateTable(identity_autoincrement_table) + actual = sql_compiler(create_table) + expected = ( + "CREATE TABLE identity (" + "\tid INTEGER NOT NULL IDENTITY(1,1) ORDER, " + "\tidentity_col_unordered INTEGER NOT NULL IDENTITY NOORDER, " + "\tidentity_col INTEGER NOT NULL IDENTITY, " + "\tPRIMARY KEY (id))" + ) + assert actual == expected