|
7 | 7 | from collections import defaultdict
|
8 | 8 |
|
9 | 9 | from sqlglot import exp
|
10 |
| -from sqlglot.errors import ErrorLevel, ParseError, concat_messages, merge_errors |
| 10 | +from sqlglot.errors import ErrorLevel, ParseError, TokenError, concat_messages, merge_errors |
11 | 11 | from sqlglot.helper import apply_index_offset, ensure_list, seq_get
|
12 | 12 | from sqlglot.time import format_time
|
13 | 13 | from sqlglot.tokens import Token, Tokenizer, TokenType
|
@@ -5298,28 +5298,30 @@ def _parse_types(
|
5298 | 5298 | this: t.Optional[exp.Expression] = None
|
5299 | 5299 | prefix = self._match_text_seq("SYSUDTLIB", ".")
|
5300 | 5300 |
|
5301 |
| - if not self._match_set(self.TYPE_TOKENS): |
| 5301 | + if self._match_set(self.TYPE_TOKENS): |
| 5302 | + type_token = self._prev.token_type |
| 5303 | + else: |
| 5304 | + type_token = None |
5302 | 5305 | identifier = allow_identifiers and self._parse_id_var(
|
5303 | 5306 | any_token=False, tokens=(TokenType.VAR,)
|
5304 | 5307 | )
|
5305 | 5308 | if isinstance(identifier, exp.Identifier):
|
5306 |
| - tokens = self.dialect.tokenize(identifier.sql(dialect=self.dialect)) |
5307 |
| - |
5308 |
| - if len(tokens) != 1: |
5309 |
| - self.raise_error("Unexpected identifier", self._prev) |
| 5309 | + try: |
| 5310 | + tokens = self.dialect.tokenize(identifier.name) |
| 5311 | + except TokenError: |
| 5312 | + tokens = None |
5310 | 5313 |
|
5311 |
| - if tokens[0].token_type in self.TYPE_TOKENS: |
5312 |
| - self._prev = tokens[0] |
5313 |
| - elif self.dialect.SUPPORTS_USER_DEFINED_TYPES: |
5314 |
| - this = self._parse_user_defined_type(identifier) |
| 5314 | + if tokens and len(tokens) == 1 and tokens[0].token_type in self.TYPE_TOKENS: |
| 5315 | + type_token = tokens[0].token_type |
5315 | 5316 | else:
|
5316 |
| - self._retreat(self._index - 1) |
5317 |
| - return None |
| 5317 | + if self.dialect.SUPPORTS_USER_DEFINED_TYPES: |
| 5318 | + this = self._parse_user_defined_type(identifier) |
| 5319 | + else: |
| 5320 | + self._retreat(self._index - 1) |
| 5321 | + return None |
5318 | 5322 | else:
|
5319 | 5323 | return None
|
5320 | 5324 |
|
5321 |
| - type_token = self._prev.token_type |
5322 |
| - |
5323 | 5325 | if type_token == TokenType.PSEUDO_TYPE:
|
5324 | 5326 | return self.expression(exp.PseudoType, this=self._prev.text.upper())
|
5325 | 5327 |
|
|
0 commit comments