fakesnow
fakesnow copied to clipboard
AUTO_INCREMENT is not supported
Autoincrement is not supported in duckdb and when transpiling snowflake statements using this modifier sqlglot generates invalid code that raise the following error:
duckdb.duckdb.ParserException: Parser Error: syntax error at or near "AUTO_INCREMENT"
Below is a snippet that shows the error
>>> import sqlglot
>>> q = "CREATE TABLE test_table (id NUMERIC NOT NULL AUTOINCREMENT)"
>>> sqlglot.parse_one(q, read="snowflake").sql("duckdb")
'CREATE TABLE test_table (id DECIMAL(38, 0) NOT NULL AUTO_INCREMENT)'
And here is a playground snippet showing the error.
To fully support this, we would need to use sequences, which then are used as default values as explained in this SO answer. The above statement could be converted to something like:
CREATE SEQUENCE test_table_id_seq START 1;
CREATE TABLE test_table (id DECIMAL(38, 0) NOT NULL DEFAULT NEXTVAL('test_table_id_seq'))
I filed an issue on sqlgot, but they closed it as not planned