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

TABLE DDL with IDENTITY adds unnecessary DEFAULT #27

Closed
Stegallo opened this issue Nov 7, 2022 · 2 comments
Closed

TABLE DDL with IDENTITY adds unnecessary DEFAULT #27

Stegallo opened this issue Nov 7, 2022 · 2 comments

Comments

@Stegallo
Copy link
Contributor

Stegallo commented Nov 7, 2022

Describe the bug
I did run convert to create the yaml file of an existing table having an IDENTITY column.
The resulting yaml has default: IDENTITY START 0 INCREMENT 1.
When I run the apply, the resulting DDL is syntactically invalid.

Not exactly sure if the issue is in the way the column gets converted or in the way the DDL is created.
If the latter, the fix may be as simple as conditionally remove the keyword DEFAULT in
https://github.com/littleK0i/SnowDDL/blob/master/snowddl/resolver/table.py#L170

Expected behavior
DEFAULT keyword should not be present in column definition.

CREATE TABLE "DB_NAME"."SCHEMA_NAME"."TABLE_NAME"
(
      "ID" NUMBER(38,0) IDENTITY START 0 INCREMENT 1 NOT NULL
)

Attach log

2022-11-07 15:02:23.819 - WARNING - Resolved TABLE [DB_NAME.SCHEMA_NAME.TABLE_NAME]: ERROR
(
    message   =>  SQL compilation error:
syntax error line 3 at position 47 unexpected 'START'.
    errno     =>  1003
    sqlstate  =>  42000
    sfqid     =>  01a828c6-0605-1a48-0000-6a6d07215cee
    sql       =>  CREATE TABLE "DB_NAME"."SCHEMA_NAME"."TABLE_NAME"
(
      "ID" NUMBER(38,0) DEFAULT IDENTITY START 0 INCREMENT 1 NOT NULL
)

Attach YAML config (if applicable)

columns:
  ID:
    type: NUMBER(38,0) NOT NULL
    default: IDENTITY START 0 INCREMENT 1

thank you!

@littleK0i
Copy link
Owner

littleK0i commented Nov 9, 2022

Thank you for reporting this. I'll fix it next week when I get back from travel.

SnowDDL does not support IDENTITY for columns directly (on purpose), but we can create a config for additional SEQUENCE object automatically, and use this SEQUENCE object instead of IDENTITY.

The main problem with IDENTITY is the possibility for counter to be lost or broken during CREATE OR REPLACE TABLE command, which is required for many types of TABLE changes.

@littleK0i
Copy link
Owner

@Stegallo , please check version 0.11.0.

IDENTITY columns are now converted into sequences automatically. Current value and increment will be preserved.

Sequence name is built using the following template: {tableName}_{colName}_seq.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants