Skip to content

Recognize ROW_FORMAT as a keyword (issue773)#860

Open
apoorvdarshan wants to merge 1 commit into
andialbrecht:masterfrom
apoorvdarshan:fix-alter-table-row-format-keyword-773
Open

Recognize ROW_FORMAT as a keyword (issue773)#860
apoorvdarshan wants to merge 1 commit into
andialbrecht:masterfrom
apoorvdarshan:fix-alter-table-row-format-keyword-773

Conversation

@apoorvdarshan

Copy link
Copy Markdown

Fixes #773.

Problem

ALTER TABLE mytable ROW_FORMAT=Dynamic parses the table name and the option together as a single identifier:

>>> import sqlparse
>>> [str(t) for t in sqlparse.parse("ALTER TABLE mytable ROW_FORMAT=Dynamic")[0].tokens]
['ALTER', ' ', 'TABLE', ' ', 'mytable ROW_FORMAT', '=', 'Dynamic']
#                                ^^^^^^^^^^^^^^^^^^ table name absorbs the option

ROW_FORMAT was tokenized as a Name, so the identifier grouper treated it as an alias of mytable (mytable ROW_FORMAT).

Fix

ENGINE, AUTO_INCREMENT and similar table options are already listed in KEYWORDS, which is why ALTER TABLE mytable ENGINE=InnoDB parses correctly (the table name is a standalone identifier). This adds ROW_FORMAT to KEYWORDS for consistent behavior:

>>> [str(t) for t in sqlparse.parse("ALTER TABLE mytable ROW_FORMAT=Dynamic")[0].tokens]
['ALTER', ' ', 'TABLE', ' ', 'mytable', ' ', 'ROW_FORMAT', '=', 'Dynamic']

Verification

  • Added test_alter_table_row_format_issue773 to tests/test_regressions.py; it fails on main (no ROW_FORMAT keyword) and passes with this change.
  • Full test suite: 488 passed, 2 xfailed, 1 xpassed (the xpassed is pre-existing and identical on main); no regressions.
  • ruff check sqlparse/ (the CI lint command) is clean.
  • Added a CHANGELOG entry.

Disclosure: this change was prepared with the assistance of an AI tool (Claude Code). I reproduced the issue, reviewed and verified the fix and test results, and take responsibility for the contribution and will respond to review feedback personally.

`ALTER TABLE mytable ROW_FORMAT=Dynamic` parsed the table name and the
option as a single identifier (`mytable ROW_FORMAT`), because ROW_FORMAT
was tokenized as a Name and treated as an alias of the table.

ENGINE, AUTO_INCREMENT and similar table options are already keywords, so
`ALTER TABLE mytable ENGINE=InnoDB` parses correctly. Add ROW_FORMAT to the
KEYWORDS dict for consistent behavior, and add a regression test.
Copilot AI review requested due to automatic review settings July 3, 2026 12:51

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This pull request fixes a MySQL-specific parsing regression where ROW_FORMAT in ALTER TABLE ... ROW_FORMAT=... was tokenized as a Name, causing the table name and option to be grouped into a single identifier. It does so by recognizing ROW_FORMAT as a keyword and adds a regression test and changelog entry to lock in the behavior.

Changes:

  • Add ROW_FORMAT to the keyword set so it’s tokenized as Keyword rather than Name.
  • Add a regression test ensuring ROW_FORMAT is not absorbed as a table alias in ALTER TABLE.
  • Document the fix in the CHANGELOG.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
tests/test_regressions.py Adds a regression test covering ALTER TABLE ... ROW_FORMAT=... tokenization and identifier grouping.
sqlparse/keywords.py Registers ROW_FORMAT as a Keyword to prevent incorrect identifier alias grouping.
CHANGELOG Notes the bug fix for issue #773.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/test_regressions.py
Comment on lines +460 to +462
p = sqlparse.parse('ALTER TABLE mytable ROW_FORMAT=Dynamic')[0]
row_format = p.token_next_by(m=(T.Keyword, 'ROW_FORMAT'))[1]
assert row_format is not None
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.

Unable to parse ALTER statement with ROW_FORMAT into correct tokens

2 participants