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

Snowflake Alter Table ... Add Column ... WITH TAG (...) doesn't parse correctly #3537

Closed
barino86 opened this issue May 23, 2024 · 1 comment · Fixed by #3549
Closed

Snowflake Alter Table ... Add Column ... WITH TAG (...) doesn't parse correctly #3537

barino86 opened this issue May 23, 2024 · 1 comment · Fixed by #3549
Assignees

Comments

@barino86
Copy link

Before you file an issue

  • Make sure you specify the "read" dialect eg. parse_one(sql, read="spark"): snowflake
  • Make sure you specify the "write" dialect eg. ast.sql(dialect="duckdb"): snowflake
  • Check if the issue still exists on main

Fully reproducible code snippet
Please include a fully reproducible code snippet or the input sql, dialect, and expected output.

Snowflake syntax allows an optional WITH token to add a column with a tag, however, the parser doesn't like the WITH token in this position. If the WITH token is removed the parser doesn't know how to parse the TAG syntax for added columns.

This example doesn't understand the WITH token as part of the Add Column query:

from sqlglot import parse_one

query = """
    ALTER TABLE db_name.schmaName.tblName add column COLUMN_1 varchar not null WITH TAG (key1 = 'value_1');
"""
parsed = parse_one(query, read='snowflake')
print(repr(parsed))

...
sqlglot.errors.ParseError: Expecting (. Line 2, Col: 84.
            ALTER TABLE db_name.schmaName.tblName add column COLUMN_1 varchar not null TAG (key1 = 'value_1');

This example doesn't raise an exception but still doesn't know how to parse the query to add a column with a tag.

from sqlglot import parse_one

query = """
    ALTER TABLE db_name.schmaName.tblName add column COLUMN_1 varchar not null TAG (key1 = 'value_1');
"""
parsed = parse_one(query, read='snowflake')
print(repr(parsed))

...
'ALTER TABLE db_name.schmaName.tblName add column COLUMN_1 varchar not null TAG (key1 = 'value_1')' contains unsupported syntax. Falling back to parsing as a 'Command'.
Command(this=ALTER, expression=TABLE db_name.schmaName.tblName add column COLUMN_1 varchar not null TAG (key1 = 'value_1'))
...

Official Documentation
Please include links to official SQL documentation related to your issue.
https://docs.snowflake.com/en/sql-reference/sql/alter-table#table-column-actions-tablecolumnaction

@barino86
Copy link
Author

barino86 commented May 25, 2024

Will this also take care of the case for ALTER TABLE ... ALTER COLUMN ... SET TAG tag1 = 'value1'
?

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 a pull request may close this issue.

2 participants