Skip to content

Commit a88dfce

Browse files
authored
fix(mysql): support SHOW TABLES IN <schema> parsing (#7537)
MariaDB and MySQL both accept `SHOW TABLES IN schema` as a synonym for `SHOW TABLES FROM schema`, but the parser only handled `FROM`. The `IN` token was being consumed as a potential log-file specifier (for BINLOG/RELAYLOG EVENTS) and then lost, leaving the schema identifier unconsumed and raising a ParseError. Save the parser index before consuming `IN`; if no string literal follows, retreat so the schema-name branch can match `IN` as an alias for `FROM`. BINLOG/RELAYLOG EVENTS behavior is preserved by the existing test_show_events coverage.
1 parent 68861d9 commit a88dfce

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

sqlglot/parsers/mysql.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,13 @@ def _parse_show_mysql(
408408
else:
409409
target_id = None
410410

411-
log = self._parse_string() if self._match_text_seq("IN") else None
411+
index = self._index
412+
if self._match_text_seq("IN"):
413+
log = self._parse_string()
414+
if log is None:
415+
self._retreat(index)
416+
else:
417+
log = None
412418

413419
if this in ("BINLOG EVENTS", "RELAYLOG EVENTS"):
414420
position = self._parse_number() if self._match_text_seq("FROM") else None
@@ -417,7 +423,7 @@ def _parse_show_mysql(
417423
position = None
418424
db = None
419425

420-
if self._match(TokenType.FROM):
426+
if self._match(TokenType.FROM) or self._match_text_seq("IN"):
421427
db = self._parse_id_var()
422428
elif self._match(TokenType.DOT):
423429
db = target_id

tests/dialects/test_mysql.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1411,6 +1411,14 @@ def test_show_tables(self):
14111411
self.assertIsInstance(show.args["like"], exp.Literal)
14121412
self.assertEqual(show.text("like"), "%foo%")
14131413

1414+
show = self.validate_identity("SHOW TABLES IN test", "SHOW TABLES FROM test")
1415+
self.assertEqual(show.name, "TABLES")
1416+
self.assertEqual(show.text("db"), "test")
1417+
1418+
show = self.validate_identity("SHOW FULL TABLES IN test", "SHOW FULL TABLES FROM test")
1419+
self.assertTrue(show.args["full"])
1420+
self.assertEqual(show.text("db"), "test")
1421+
14141422
def test_set_variable(self):
14151423
cmd = self.parse_one("SET SESSION x = 1")
14161424
item = cmd.expressions[0]

0 commit comments

Comments
 (0)