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

Fix(snowflake): parse CREATE SEQUENCE with commas #3436

Merged
merged 1 commit into from
May 8, 2024

Conversation

georgesittas
Copy link
Collaborator

@georgesittas georgesittas commented May 8, 2024

Fixes #3435

Note that the two DDLs tested produce slightly different ASTs:

>>> import sqlglot
>>> sqlglot.parse_one("CREATE SEQUENCE seq1 WITH START=1 INCREMENT=1 ORDER", "snowflake")
Create(
  this=Table(
    this=Identifier(this=seq1, quoted=False)),
  kind=SEQUENCE,
  properties=Properties(
    expressions=[
      Property(
        this=Identifier(this=START, quoted=False),
        value=Literal(this=1, is_string=False)),
      Property(
        this=Identifier(this=INCREMENT, quoted=False),
        value=Literal(this=1, is_string=False)),
      SequenceProperties(
        options=[
          Var(this=ORDER)])]))
>>> sqlglot.parse_one("CREATE SEQUENCE seq1 WITH START=1, INCREMENT=1 ORDER", "snowflake")
Create(
  this=Table(
    this=Identifier(this=seq1, quoted=False)),
  kind=SEQUENCE,
  properties=Properties(
    expressions=[
      Property(
        this=Identifier(this=START, quoted=False),
        value=Literal(this=1, is_string=False)),
      SequenceProperties(
        increment=Literal(this=1, is_string=False),
        options=[
          Var(this=ORDER)])]))

This happens because when we only have KEY=VALUE pairs separated by whitespace we don't ever reach _parse_sequence_properties, but when there's a comma we do reach it and so the SequenceProperties is produced. It's not 100% clean but not sure if a refactor is high ROI right now to make the two ASTs match.

@georgesittas georgesittas merged commit 273731f into main May 8, 2024
5 checks passed
@georgesittas georgesittas deleted the jo/snowflake_sequence_ddl_fixup branch May 8, 2024 22:01
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

Successfully merging this pull request may close these issues.

Allow comma-separated values for CREATE SEQUENCE properties (Snowflake)
2 participants