Skip to content

Commit

Permalink
Fix: allow parsing 'if' as an identifier (#1517)
Browse files Browse the repository at this point in the history
  • Loading branch information
georgesittas authored May 2, 2023
1 parent 52ab03d commit c3db2b8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
6 changes: 6 additions & 0 deletions sqlglot/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -3450,7 +3450,13 @@ def _parse_if(self) -> t.Optional[exp.Expression]:
self.validate_expression(this, args)
self._match_r_paren()
else:
index = self._index - 1
condition = self._parse_conjunction()

if not condition:
self._retreat(index)
return None

self._match(TokenType.THEN)
true = self._parse_conjunction()
false = self._parse_conjunction() if self._match(TokenType.ELSE) else None
Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/identity.sql
Original file line number Diff line number Diff line change
Expand Up @@ -817,3 +817,4 @@ JSON_OBJECT('x': NULL, 'y': 1 WITH UNIQUE KEYS)
JSON_OBJECT('x': NULL, 'y': 1 ABSENT ON NULL WITH UNIQUE KEYS)
JSON_OBJECT('x': 1 RETURNING VARCHAR(100))
JSON_OBJECT('x': 1 RETURNING VARBINARY FORMAT JSON ENCODING UTF8)
SELECT if.x

0 comments on commit c3db2b8

Please sign in to comment.