Skip to content

Commit

Permalink
Fix(parser): ensure identifiers aren't treated as NO_PAREN_FUNCTIONS (#…
Browse files Browse the repository at this point in the history
…2056)

* Fix(parser): ensure identifiers aren't treated as NO_PAREN_FUNCTIONS

* Create a set with tokens that can't be used as no paren func names
  • Loading branch information
georgesittas authored Aug 14, 2023
1 parent c37abfd commit 96d4d8b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
7 changes: 6 additions & 1 deletion sqlglot/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,11 @@ class Parser(metaclass=_Parser):
"NEXT": lambda self: self._parse_next_value_for(),
}

INVALID_FUNC_NAME_TOKENS = {
TokenType.IDENTIFIER,
TokenType.STRING,
}

FUNCTIONS_WITH_ALIASED_ARGS = {"STRUCT"}

FUNCTION_PARSERS = {
Expand Down Expand Up @@ -3356,7 +3361,7 @@ def _parse_function(
upper = this.upper()

parser = self.NO_PAREN_FUNCTION_PARSERS.get(upper)
if optional_parens and parser:
if optional_parens and parser and token_type not in self.INVALID_FUNC_NAME_TOKENS:
self._advance()
return parser(self)

Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/identity.sql
Original file line number Diff line number Diff line change
Expand Up @@ -855,3 +855,4 @@ SELECT * FROM (tbl1 CROSS JOIN (SELECT * FROM tbl2) AS t1)
/* comment1 */ DELETE FROM x /* comment2 */ WHERE y > 1
/* comment */ CREATE TABLE foo AS SELECT 1
SELECT next, transform, if
SELECT "any", "case", "if", "next"
3 changes: 3 additions & 0 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,9 @@ def test_parse_errors(self):
with self.assertRaises(ParseError):
parse_one("IF(a > 0)")

with self.assertRaises(ParseError):
parse_one("SELECT CASE FROM x")

with self.assertRaises(ParseError):
parse_one("WITH cte AS (SELECT * FROM x)")

Expand Down

0 comments on commit 96d4d8b

Please sign in to comment.