Skip to content

fix(mysql): support SHOW TABLES IN <schema> parsing#7537

Open
mkcorneli wants to merge 1 commit intotobymao:mainfrom
mkcorneli:fix/mysql-show-tables-in
Open

fix(mysql): support SHOW TABLES IN <schema> parsing#7537
mkcorneli wants to merge 1 commit intotobymao:mainfrom
mkcorneli:fix/mysql-show-tables-in

Conversation

@mkcorneli
Copy link
Copy Markdown

Summary

MariaDB and MySQL both accept SHOW TABLES IN schema as a synonym for SHOW TABLES FROM schema, but the parser only handled FROM. This PR teaches _parse_show_mysql to also accept IN as a schema-name alias without breaking the existing log-file handling for SHOW BINLOG EVENTS IN 'logfile'.

Before

>>> sqlglot.parse_one("SHOW TABLES IN test", dialect="mysql")
ParseError: Invalid expression / Unexpected token. Line 1, Col: 19.

After

>>> sqlglot.parse_one("SHOW TABLES IN test", dialect="mysql").sql(dialect="mysql")
'SHOW TABLES FROM test'

Why it broke

The IN token was being consumed unconditionally as a potential log-file specifier. When followed by an identifier (e.g. test) rather than a string literal, _parse_string() returned None but IN was already consumed — leaving the schema identifier as an unexpected token.

Fix

Save the parser index before consuming IN; if no string literal follows, _retreat(index) so the schema-name branch can match IN as an alias for FROM. BINLOG/RELAYLOG EVENTS behavior is preserved because those variants always have a string literal following IN.

Test plan

  • New assertions in test_show_tables cover SHOW TABLES IN test and SHOW FULL TABLES IN test round-trips
  • Pre-existing test_show_events (line 1175) still passes — confirms SHOW BINLOG EVENTS IN 'log' FROM 1 LIMIT 2, 3 regression guard
  • Full tests/dialects/ suite runs cleanly (no new failures vs. main)
  • ruff check + ruff format --check pass

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant