fakesnow icon indicating copy to clipboard operation
fakesnow copied to clipboard

CREATE SEQUENCE fails with cursor description

Open tharwan opened this issue 1 year ago • 8 comments

from snowflake.sqlalchemy import URL
import sqlalchemy
import fakesnow

with fakesnow.patch():
    engine = sqlalchemy.create_engine(
        URL(
            account="abc123",
            user="testuser1",
            password="0123456",
            database="testdb",
            schema="public",
        )
    )

    with engine.connect() as con:
        print(con.execute("CREATE SEQUENCE insertion_id_seq START WITH 1").fetchall())

related to #40, the cursor description fails.

tharwan avatar Feb 12 '24 12:02 tharwan

The same approach to fix #40 should work here if you'd like to have a go?

tekumara avatar Feb 12 '24 12:02 tekumara

yes! I will open a PR later today.

tharwan avatar Feb 12 '24 12:02 tharwan

looking a little bit deeper it seems that sequences in general are not really working, because snowflake uses seq1.nextval but duckdb nextval(seq1). Which is also not supported currently in sqlglot. So I need another workaround for my tests anyway.

tharwan avatar Feb 12 '24 12:02 tharwan

Ah right.. so we probably also need a transformation from seq1.nextval -> nextval(seq1). fakesnow has a bunch of specialised transformations that live outside sqlglot.

tekumara avatar Feb 13 '24 11:02 tekumara

The other problem is that in the case of create sequence, sqlglot does not recognize sequence as token, and therefore also not the rest of the command like the name.

tharwan avatar Feb 13 '24 11:02 tharwan

Ah right. I've found the sqlglot folks receptive to PRs that add more precise parsing.

tekumara avatar Feb 14 '24 12:02 tekumara

I've added support for parsing CREATE SEQUENCE to sqlglot here, if that helps?

tekumara avatar Mar 09 '24 03:03 tekumara

Amazing, thanks!

tharwan avatar Mar 09 '24 06:03 tharwan