Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ORDER/NOORDER for IDENTITY #500

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/snowflake/sqlalchemy/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
26 changes: 26 additions & 0 deletions tests/test_sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from sqlalchemy import (
Column,
Identity,
Integer,
MetaData,
Sequence,
Expand All @@ -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):
Expand Down Expand Up @@ -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
Loading