Skip to content

Commit

Permalink
Fix(parser): don't consume identifier in unnamed constraint parser (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
georgesittas authored Oct 5, 2023
1 parent 2bcd3e7 commit dd8334d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 3 additions & 1 deletion sqlglot/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -3892,7 +3892,9 @@ def _parse_constraint(self) -> t.Optional[exp.Expression]:
def _parse_unnamed_constraint(
self, constraints: t.Optional[t.Collection[str]] = None
) -> t.Optional[exp.Expression]:
if not self._match_texts(constraints or self.CONSTRAINT_PARSERS):
if self._match(TokenType.IDENTIFIER, advance=False) or not self._match_texts(
constraints or self.CONSTRAINT_PARSERS
):
return None

constraint = self._prev.text.upper()
Expand Down
3 changes: 3 additions & 0 deletions tests/dialects/test_mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ def test_ddl(self):
self.validate_identity("CREATE TABLE foo (a BIGINT, INDEX USING BTREE (b))")
self.validate_identity("CREATE TABLE foo (a BIGINT, FULLTEXT INDEX (b))")
self.validate_identity("CREATE TABLE foo (a BIGINT, SPATIAL INDEX (b))")
self.validate_identity(
"CREATE TABLE `oauth_consumer` (`key` VARCHAR(32) NOT NULL, UNIQUE `OAUTH_CONSUMER_KEY` (`key`))"
)
self.validate_identity(
"CREATE TABLE `x` (`username` VARCHAR(200), PRIMARY KEY (`username`(16)))"
)
Expand Down

0 comments on commit dd8334d

Please sign in to comment.