Is there an option to leave the default identity/autoincrement column #139
Replies: 2 comments 2 replies
-
Interesting question. Standard "autoincrement" is actually unsafe. It creates a hidden sequence, which is attached to table. When you eventually have to run But if some additional rows are inserted into table in the moment between generation and actual execution of Explicitly created That's why SnowDDL explicitly insists on using Unless Snowflake provides a way to safely replace tables with "autoincrement" columns, implementing it does not make much sense. But Snowflake allows to change DEFAULT value for columns to point from one sequence to another. It definitely works for proper sequence, but maybe it can also work when switching from implicit to explicit sequence. If it works, we might be able to create sequence objects and switch existing tables without REPLACE. I'll test it today. |
Beta Was this translation helpful? Give feedback.
-
Did some tests. And switching from implicit sequence to explicit sequence does not work. On top of that, it does not seem to be possible to obtain current value of implicit sequence AND use it in So.. the best case scenario for you would be converting everything to explicit sequences. In the long term it seems the only sensible option. As a temporary solution, you may try to set For converter, take this: https://github.com/littleK0i/SnowDDL/blob/master/snowddl/converter/table.py#L125-L140 And replace with something like: if c["default"]:
if str(c["default"]).upper().endswith(".NEXTVAL"):
col["default_sequence"] = self._normalise_name_with_prefix(str(c["default"])[:-8])
else:
col["default"] = str(c["default"]) In converted YAML config for table it should look like this:
|
Beta Was this translation helpful? Give feedback.
-
Currently the column with a default value like
IDENTITY START 1 INCREMENT 1 ORDER
is changed to a sequence. And the corresponding DDL would be aCREATE OR REPLACE TABLE .. COPY …
statement. This DDL is costly.In most cases the ID column would be keep stable. It is likely that other columns would be changed, and an
alter
statement is sufficient for the operation. However, if there is anidentity
column inside the table, thereplace
would always happen.So, is there an option to leave the default identity/autoincrement column as it is, rather than replacing it with a sequence?
Thank you!
Beta Was this translation helpful? Give feedback.
All reactions