Skip to content

Commit e2d6bfe

Browse files
authored
feat(mysql): parse ALTER TABLE AUTO_INCREMENT. (#7520)
MySQL allows setting the auto-increment counter on an existing table. The property parser already existed for `CREATE TABLE`; this wires it into `ALTER TABLE` as well.
1 parent 7660486 commit e2d6bfe

2 files changed

Lines changed: 8 additions & 0 deletions

File tree

sqlglot/parsers/mysql.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ class MySQLParser(parser.Parser):
253253
ALTER_PARSERS = {
254254
**parser.Parser.ALTER_PARSERS,
255255
"MODIFY": lambda self: self._parse_alter_table_alter(),
256+
"AUTO_INCREMENT": lambda self: self._parse_property_assignment(exp.AutoIncrementProperty),
256257
}
257258

258259
ALTER_ALTER_PARSERS = {

tests/dialects/test_mysql.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def test_ddl(self):
3434
self.validate_identity("ALTER TABLE t ADD INDEX `i` (`c`)")
3535
self.validate_identity("ALTER TABLE t ADD UNIQUE `i` (`c`)")
3636
self.validate_identity("ALTER TABLE test_table MODIFY COLUMN test_column LONGTEXT")
37+
self.validate_identity("ALTER TABLE t AUTO_INCREMENT=3000000000")
3738
self.validate_identity("ALTER VIEW v AS SELECT a, b, c, d FROM foo")
3839
self.validate_identity("ALTER VIEW v AS SELECT * FROM foo WHERE c > 100")
3940
self.validate_identity(
@@ -1694,3 +1695,9 @@ def test_invisible_column(self):
16941695

16951696
expr = self.parse_one("ALTER TABLE t ADD COLUMN c INT INVISIBLE")
16961697
self.assertIsNotNone(expr.find(exp.InvisibleColumnConstraint))
1698+
1699+
def test_alter_table_auto_increment(self):
1700+
prop = self.parse_one("ALTER TABLE t AUTO_INCREMENT=3000000000").find(
1701+
exp.AutoIncrementProperty
1702+
)
1703+
self.assertEqual(prop.this.to_py(), 3000000000)

0 commit comments

Comments
 (0)