Skip to content

Commit

Permalink
fix(tsql): remove BEGIN from identifiers (#4695)
Browse files Browse the repository at this point in the history
* fix(tsql): remove BEGIN from identifiers

* PR feedback 1
  • Loading branch information
geooo109 authored Feb 3, 2025
1 parent 47c0236 commit 1904b76
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
7 changes: 7 additions & 0 deletions sqlglot/dialects/tsql.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,13 @@ class Parser(parser.Parser):
TokenType.OPTION: lambda self: ("options", self._parse_options()),
}

# T-SQL does not allow BEGIN to be used as an identifier
ID_VAR_TOKENS = parser.Parser.ID_VAR_TOKENS - {TokenType.BEGIN}
ALIAS_TOKENS = parser.Parser.ALIAS_TOKENS - {TokenType.BEGIN}
TABLE_ALIAS_TOKENS = parser.Parser.TABLE_ALIAS_TOKENS - {TokenType.BEGIN}
COMMENT_TABLE_ALIAS_TOKENS = parser.Parser.COMMENT_TABLE_ALIAS_TOKENS - {TokenType.BEGIN}
UPDATE_ALIAS_TOKENS = parser.Parser.UPDATE_ALIAS_TOKENS - {TokenType.BEGIN}

FUNCTIONS = {
**parser.Parser.FUNCTIONS,
"CHARINDEX": lambda args: exp.StrPosition(
Expand Down
2 changes: 0 additions & 2 deletions sqlglot/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,8 +558,6 @@ class Parser(metaclass=_Parser):
}
ID_VAR_TOKENS.remove(TokenType.UNION)

INTERVAL_VARS = ID_VAR_TOKENS - {TokenType.END}

TABLE_ALIAS_TOKENS = ID_VAR_TOKENS - {
TokenType.ANTI,
TokenType.APPLY,
Expand Down
3 changes: 3 additions & 0 deletions tests/dialects/test_tsql.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,9 @@ def test_tsql(self):
},
)

with self.assertRaises(ParseError):
parse_one("SELECT begin", read="tsql")

def test_option(self):
possible_options = [
"HASH GROUP",
Expand Down

0 comments on commit 1904b76

Please sign in to comment.