Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parser: fix cast function restore #40129

Merged
merged 1 commit into from
Dec 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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