Skip to content

Commit

Permalink
parser: fix cast function restore (#40129)
Browse files Browse the repository at this point in the history
close #40130
  • Loading branch information
xiongjiwei authored Dec 23, 2022
1 parent 53edd89 commit 18c71f4
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
1 change: 1 addition & 0 deletions parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3244,6 +3244,7 @@ func TestDDL(t *testing.T) {
{"create table t (a bigint, b bigint as (a+1) not null);", true, "CREATE TABLE `t` (`a` BIGINT,`b` BIGINT GENERATED ALWAYS AS(`a`+1) VIRTUAL NOT NULL)"},
{"create table t (a bigint, b bigint as (a+1) not null);", true, "CREATE TABLE `t` (`a` BIGINT,`b` BIGINT GENERATED ALWAYS AS(`a`+1) VIRTUAL NOT NULL)"},
{"create table t (a bigint, b bigint as (a+1) not null comment 'ttt');", true, "CREATE TABLE `t` (`a` BIGINT,`b` BIGINT GENERATED ALWAYS AS(`a`+1) VIRTUAL NOT NULL COMMENT 'ttt')"},
{"create table t(a int, index idx((cast(a as binary(1)))));", true, "CREATE TABLE `t` (`a` INT,INDEX `idx`((CAST(`a` AS BINARY(1)))))"},
{"alter table t add column (f timestamp as (a+1) default '2019-01-01 11:11:11');", false, ""},
{"alter table t modify column f int as (a+1) default 55;", false, ""},

Expand Down
2 changes: 1 addition & 1 deletion parser/types/field_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ func (ft *FieldType) Restore(ctx *format.RestoreCtx) error {
// RestoreAsCastType is used for write AST back to string.
func (ft *FieldType) RestoreAsCastType(ctx *format.RestoreCtx, explicitCharset bool) {
switch ft.tp {
case mysql.TypeVarString:
case mysql.TypeVarString, mysql.TypeString:
skipWriteBinary := false
if ft.charset == charset.CharsetBin && ft.collate == charset.CollationBin {
ctx.WriteKeyWord("BINARY")
Expand Down

0 comments on commit 18c71f4

Please sign in to comment.