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

VALUES syntax in parenthesis raises a ParserError for Snowflake ❄️ #1768

Closed
florian-ernst-alan opened this issue Jun 13, 2023 · 0 comments
Assignees

Comments

@florian-ernst-alan
Copy link
Contributor

This is the last error I have on our entire codebase 🎉 all other queries are correctly parsed under sqlglot-16.0.1.dev10

This query works in Snowflake, but fails to get parsed:

SELECT * FROM (VALUES (0) foo(bar))

The following code was used:

parse_one("SELECT * FROM (VALUES (0) foo(bar))", read=dialects.Snowflake)

It is only because of the outer parenthesis. The following code samples work, and are correctly parsed:

-- Sample 1 ✅ 
SELECT *
FROM VALUES (0) foo(bar)

-- Sample 2 ✅ 
SELECT *
FROM (VALUES (0)) foo(bar)
Here is the tracelog:

Traceback (most recent call last):
  File "/Users/florian.ernst/Library/Application Support/JetBrains/Toolbox/apps/PyCharm-P/ch-0/231.9011.38/PyCharm.app/Contents/plugins/python/helpers/pydev/pydevconsole.py", line 364, in runcode
    coro = func()
  File "<input>", line 1, in <module>
  File "/Users/florian.ernst/Alan/alan-jobs/env/lib/python3.10/site-packages/sqlglot/__init__.py", line 158, in parse_one
    result = dialect.parse(sql, **opts)
  File "/Users/florian.ernst/Alan/alan-jobs/env/lib/python3.10/site-packages/sqlglot/dialects/dialect.py", line 217, in parse
    return self.parser(**opts).parse(self.tokenize(sql), sql)
  File "/Users/florian.ernst/Alan/alan-jobs/env/lib/python3.10/site-packages/sqlglot/parser.py", line 856, in parse
    The list of the produced syntax trees.
  File "/Users/florian.ernst/Alan/alan-jobs/env/lib/python3.10/site-packages/sqlglot/parser.py", line 922, in _parse
    self._advance()
  File "/Users/florian.ernst/Alan/alan-jobs/env/lib/python3.10/site-packages/sqlglot/parser.py", line 1112, in _parse_statement
    
  File "/Users/florian.ernst/Alan/alan-jobs/env/lib/python3.10/site-packages/sqlglot/parser.py", line 1893, in _parse_select
    this.set("into", into)
  File "/Users/florian.ernst/Alan/alan-jobs/env/lib/python3.10/site-packages/sqlglot/parser.py", line 2031, in _parse_from
    self, modifiers: bool = False, skip_from_token: bool = False
  File "/Users/florian.ernst/Alan/alan-jobs/env/lib/python3.10/site-packages/sqlglot/parser.py", line 2299, in _parse_table
    return lateral
  File "/Users/florian.ernst/Alan/alan-jobs/env/lib/python3.10/site-packages/sqlglot/parser.py", line 2372, in _parse_derived_table_values
    if not is_derived and not self._match(TokenType.VALUES):
  File "/Users/florian.ernst/Alan/alan-jobs/env/lib/python3.10/site-packages/sqlglot/parser.py", line 4585, in _match_r_paren
    if not self._curr or not self._next:
  File "/Users/florian.ernst/Alan/alan-jobs/env/lib/python3.10/site-packages/sqlglot/parser.py", line 966, in raise_error
    
sqlglot.errors.ParseError: Expecting ). Line 1, Col: 29.
  SELECT * FROM (VALUES (0) foo(bar))

Don't hesitate to ask if more information is needed 🙏

@tobymao tobymao self-assigned this Jun 13, 2023
adrianisk pushed a commit to adrianisk/sqlglot that referenced this issue Jun 21, 2023
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

No branches or pull requests

2 participants