diff --git a/sqlglot/dialects/mysql.py b/sqlglot/dialects/mysql.py index e2e41c01b5..50e7b8edb8 100644 --- a/sqlglot/dialects/mysql.py +++ b/sqlglot/dialects/mysql.py @@ -464,6 +464,7 @@ class Parser(parser.Parser): "INDEX": lambda self: self._parse_index_constraint(), "KEY": lambda self: self._parse_index_constraint(), "SPATIAL": lambda self: self._parse_index_constraint(kind="SPATIAL"), + "ZEROFILL": lambda self: self.expression(exp.ZeroFillColumnConstraint), } ALTER_PARSERS = { diff --git a/sqlglot/expressions.py b/sqlglot/expressions.py index f557b4fa34..ba6a78f5d5 100644 --- a/sqlglot/expressions.py +++ b/sqlglot/expressions.py @@ -1972,6 +1972,10 @@ class AutoIncrementColumnConstraint(ColumnConstraintKind): pass +class ZeroFillColumnConstraint(ColumnConstraint): + arg_types = {} + + class PeriodForSystemTimeConstraint(ColumnConstraintKind): arg_types = {"this": True, "expression": True} diff --git a/sqlglot/generator.py b/sqlglot/generator.py index fcc1a55150..ec83197855 100644 --- a/sqlglot/generator.py +++ b/sqlglot/generator.py @@ -5434,3 +5434,6 @@ def initcap_sql(self, expression: exp.Initcap) -> str: delimiters = None return self.func("INITCAP", expression.this, delimiters) + + def zerofillcolumnconstraint_sql(self, expression: exp.ZeroFillColumnConstraint) -> str: + return "ZEROFILL" diff --git a/tests/dialects/test_mysql.py b/tests/dialects/test_mysql.py index 54c8d8de55..05dadfb586 100644 --- a/tests/dialects/test_mysql.py +++ b/tests/dialects/test_mysql.py @@ -26,6 +26,7 @@ def test_ddl(self): self.validate_identity("CREATE TABLE foo (a BIGINT, INDEX USING BTREE (b))") self.validate_identity("CREATE TABLE foo (a BIGINT, FULLTEXT INDEX (b))") self.validate_identity("CREATE TABLE foo (a BIGINT, SPATIAL INDEX (b))") + self.validate_identity("CREATE TABLE foo (a INT UNSIGNED ZEROFILL)") self.validate_identity("ALTER TABLE t1 ADD COLUMN x INT, ALGORITHM=INPLACE, LOCK=EXCLUSIVE") self.validate_identity("ALTER TABLE t ADD INDEX `i` (`c`)") self.validate_identity("ALTER TABLE t ADD UNIQUE `i` (`c`)")