Conversation
An `ALTER TABLE` in MySQL allows table options to be passed without
commas,
```
ALTER TABLE tbl_name
[alter_option [, alter_option] ...]
[partition_options]
alter_option: {
table_options
...
table_options:
table_option [[,] table_option] ...
```
This commit adds `OPTIONAL_COMMA_BETWEEN_ALTER_TABLE_OPTIONS`, which,
when `True`, correctly parses a query like
```sql
ALTER TABLE t ADD i int, ENGINE=INNODB COMMENT='hi' AUTO_INCREMENT=5
```
Adding this support in MySQL raised a small issue, where `CHARSET` is a
valid alias of `CHARACTER SET`, but was otherwise parsed as a table
option.
Contributor
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The changes align with existing parser behavior and include focused regression coverage, with no confirmed blocking issues.
Review effort: Balanced
Findings: None
What changed in this PR
Extends SQLGlot’s MySQL DDL parser to accept table options without commas and recognize column-level CHARSET aliases.
Changes:
- Enables optional commas between MySQL
ALTER TABLEoptions. - Adds
CHARSETcolumn-constraint parsing. - Adds regression coverage for mixed options, charset handling, and comments.
| File | Description |
|---|---|
| tests/dialects/test_mysql.py | Adds DDL parsing and expression assertions. |
| sqlglot/parsers/mysql.py | Enables optional commas and column CHARSET support. |
| sqlglot/parser.py | Adds configurable ALTER option parsing and property separator handling. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
The `CHAR SET` syntax is a synonym for `CHARACTER SET` and `CHARSET`, which the MySQL parser fails to parse.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
An
ALTER TABLEin MySQL allows table options to be passed without commas,This commit adds
OPTIONAL_COMMA_BETWEEN_ALTER_TABLE_OPTIONS, which, whenTrue, correctly parses a query likeAdding this support in MySQL raised a small issue, where
CHARSETis a valid alias ofCHARACTER SET, but was otherwise parsed as a table option.