Skip to content

Commit 4ae76e5

Browse files
committed
feat(mysql): support ZEROFILL column attribute
This fixes parsing errors encountered when processing legacy MySQL schemas containing numeric columns with the zerofill property.
1 parent 67f499d commit 4ae76e5

File tree

4 files changed

+9
-0
lines changed

4 files changed

+9
-0
lines changed

sqlglot/dialects/mysql.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,7 @@ class Parser(parser.Parser):
464464
"INDEX": lambda self: self._parse_index_constraint(),
465465
"KEY": lambda self: self._parse_index_constraint(),
466466
"SPATIAL": lambda self: self._parse_index_constraint(kind="SPATIAL"),
467+
"ZEROFILL": lambda self: self.expression(exp.ZeroFillColumnConstraint),
467468
}
468469

469470
ALTER_PARSERS = {

sqlglot/expressions.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1972,6 +1972,10 @@ class AutoIncrementColumnConstraint(ColumnConstraintKind):
19721972
pass
19731973

19741974

1975+
class ZeroFillColumnConstraint(ColumnConstraint):
1976+
arg_types = {}
1977+
1978+
19751979
class PeriodForSystemTimeConstraint(ColumnConstraintKind):
19761980
arg_types = {"this": True, "expression": True}
19771981

sqlglot/generator.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5434,3 +5434,6 @@ def initcap_sql(self, expression: exp.Initcap) -> str:
54345434
delimiters = None
54355435

54365436
return self.func("INITCAP", expression.this, delimiters)
5437+
5438+
def zerofillcolumnconstraint_sql(self, expression: exp.ZeroFillColumnConstraint) -> str:
5439+
return "ZEROFILL"

tests/dialects/test_mysql.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def test_ddl(self):
2626
self.validate_identity("CREATE TABLE foo (a BIGINT, INDEX USING BTREE (b))")
2727
self.validate_identity("CREATE TABLE foo (a BIGINT, FULLTEXT INDEX (b))")
2828
self.validate_identity("CREATE TABLE foo (a BIGINT, SPATIAL INDEX (b))")
29+
self.validate_identity("CREATE TABLE foo (a INT UNSIGNED ZEROFILL)")
2930
self.validate_identity("ALTER TABLE t1 ADD COLUMN x INT, ALGORITHM=INPLACE, LOCK=EXCLUSIVE")
3031
self.validate_identity("ALTER TABLE t ADD INDEX `i` (`c`)")
3132
self.validate_identity("ALTER TABLE t ADD UNIQUE `i` (`c`)")

0 commit comments

Comments
 (0)