From c205b75e5f719dacc997c814229aa9998871a7f5 Mon Sep 17 00:00:00 2001 From: xiongjiwei Date: Fri, 23 Dec 2022 14:52:47 +0900 Subject: [PATCH] fix cast function restore --- parser/parser_test.go | 1 + parser/types/field_type.go | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/parser/parser_test.go b/parser/parser_test.go index 98f90a0104a5c..dae08a80afde3 100644 --- a/parser/parser_test.go +++ b/parser/parser_test.go @@ -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, ""}, diff --git a/parser/types/field_type.go b/parser/types/field_type.go index ff0ac9793cf17..991dc3d087d75 100644 --- a/parser/types/field_type.go +++ b/parser/types/field_type.go @@ -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")