Skip to content

Commit 1904b76

Browse files
authored
fix(tsql): remove BEGIN from identifiers (#4695)
* fix(tsql): remove BEGIN from identifiers * PR feedback 1
1 parent 47c0236 commit 1904b76

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

sqlglot/dialects/tsql.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,13 @@ class Parser(parser.Parser):
545545
TokenType.OPTION: lambda self: ("options", self._parse_options()),
546546
}
547547

548+
# T-SQL does not allow BEGIN to be used as an identifier
549+
ID_VAR_TOKENS = parser.Parser.ID_VAR_TOKENS - {TokenType.BEGIN}
550+
ALIAS_TOKENS = parser.Parser.ALIAS_TOKENS - {TokenType.BEGIN}
551+
TABLE_ALIAS_TOKENS = parser.Parser.TABLE_ALIAS_TOKENS - {TokenType.BEGIN}
552+
COMMENT_TABLE_ALIAS_TOKENS = parser.Parser.COMMENT_TABLE_ALIAS_TOKENS - {TokenType.BEGIN}
553+
UPDATE_ALIAS_TOKENS = parser.Parser.UPDATE_ALIAS_TOKENS - {TokenType.BEGIN}
554+
548555
FUNCTIONS = {
549556
**parser.Parser.FUNCTIONS,
550557
"CHARINDEX": lambda args: exp.StrPosition(

sqlglot/parser.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -558,8 +558,6 @@ class Parser(metaclass=_Parser):
558558
}
559559
ID_VAR_TOKENS.remove(TokenType.UNION)
560560

561-
INTERVAL_VARS = ID_VAR_TOKENS - {TokenType.END}
562-
563561
TABLE_ALIAS_TOKENS = ID_VAR_TOKENS - {
564562
TokenType.ANTI,
565563
TokenType.APPLY,

tests/dialects/test_tsql.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,9 @@ def test_tsql(self):
453453
},
454454
)
455455

456+
with self.assertRaises(ParseError):
457+
parse_one("SELECT begin", read="tsql")
458+
456459
def test_option(self):
457460
possible_options = [
458461
"HASH GROUP",

0 commit comments

Comments
 (0)