diff --git a/parser/ast/ddl.go b/parser/ast/ddl.go index b51ebedfd729f..0c0090e353f77 100644 --- a/parser/ast/ddl.go +++ b/parser/ast/ddl.go @@ -2298,7 +2298,7 @@ func (n *TableOption) Restore(ctx *format.RestoreCtx) error { case TableOptionInsertMethod: ctx.WriteKeyWord("INSERT_METHOD ") ctx.WritePlain("= ") - ctx.WriteString(n.StrValue) + ctx.WriteKeyWord(n.StrValue) case TableOptionTableCheckSum: ctx.WriteKeyWord("TABLE_CHECKSUM ") ctx.WritePlain("= ") diff --git a/parser/parser_test.go b/parser/parser_test.go index 7093c3889ff7a..b0fdd5a12d026 100644 --- a/parser/parser_test.go +++ b/parser/parser_test.go @@ -2979,8 +2979,8 @@ func TestDDL(t *testing.T) { {"ALTER TABLE t ENGINE = 'innodb'", true, "ALTER TABLE `t` ENGINE = innodb"}, {"ALTER TABLE t ENGINE = innodb", true, "ALTER TABLE `t` ENGINE = innodb"}, {"ALTER TABLE `db`.`t` ENGINE = ``", true, "ALTER TABLE `db`.`t` ENGINE = ''"}, - {"ALTER TABLE t INSERT_METHOD = FIRST", true, "ALTER TABLE `t` INSERT_METHOD = 'FIRST'"}, - {"ALTER TABLE t INSERT_METHOD LAST", true, "ALTER TABLE `t` INSERT_METHOD = 'LAST'"}, + {"ALTER TABLE t INSERT_METHOD = FIRST", true, "ALTER TABLE `t` INSERT_METHOD = FIRST"}, + {"ALTER TABLE t INSERT_METHOD LAST", true, "ALTER TABLE `t` INSERT_METHOD = LAST"}, {"ALTER TABLE t ADD COLUMN a SMALLINT UNSIGNED, ADD COLUMN a SMALLINT", true, "ALTER TABLE `t` ADD COLUMN `a` SMALLINT UNSIGNED, ADD COLUMN `a` SMALLINT"}, {"ALTER TABLE t ADD COLUMN a SMALLINT, ENGINE = '', default COLLATE = UTF8_GENERAL_CI", true, "ALTER TABLE `t` ADD COLUMN `a` SMALLINT, ENGINE = '', DEFAULT COLLATE = UTF8_GENERAL_CI"}, {"ALTER TABLE t ENGINE = '', COMMENT='', default COLLATE = UTF8_GENERAL_CI", true, "ALTER TABLE `t` ENGINE = '', COMMENT = '', DEFAULT COLLATE = UTF8_GENERAL_CI"}, @@ -3625,6 +3625,9 @@ func TestDDL(t *testing.T) { {"ALTER TABLE t STATS_OPTIONS=default", true, "ALTER TABLE `t` STATS_OPTIONS=DEFAULT"}, {"ALTER TABLE t STATS_OPTIONS=DeFaUlT", true, "ALTER TABLE `t` STATS_OPTIONS=DEFAULT"}, {"ALTER TABLE t STATS_OPTIONS", false, ""}, + + // Restore INSERT_METHOD table option + {"CREATE TABLE t (a int) INSERT_METHOD=FIRST", true, "CREATE TABLE `t` (`a` INT) INSERT_METHOD = FIRST"}, } RunTest(t, table, false) }