Skip to content

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

Merged
georgesittas merged 1 commit intotobymao:mainfrom
mkcorneli:fix/mysql-show-tables-in
Apr 22, 2026
Merged

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

Conversation

@mkcorneli
Copy link
Copy Markdown
Contributor

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.
Copy link
Copy Markdown
Collaborator

@georgesittas georgesittas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@georgesittas georgesittas merged commit a88dfce into tobymao:main Apr 22, 2026
8 checks passed
@mkcorneli mkcorneli deleted the fix/mysql-show-tables-in branch April 27, 2026 18:33
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.

2 participants