diff --git a/executor/insert_test.go b/executor/insert_test.go index 591f141aaba58..891728c2d050f 100644 --- a/executor/insert_test.go +++ b/executor/insert_test.go @@ -657,3 +657,11 @@ func (s *testSuite) TestPartitionInsertOnDuplicate(c *C) { tk.MustQuery(`select * from t2`).Check(testkit.Rows("1 1")) } + +func (s *testSuite) TestJiraIssue5366(c *C) { + tk := testkit.NewTestKit(c, s.store) + tk.MustExec(`use test`) + tk.MustExec(`create table bug (a varchar(100))`) + tk.MustExec(` insert into bug select ifnull(JSON_UNQUOTE(JSON_EXTRACT('[{"amount":2000,"feeAmount":0,"merchantNo":"20190430140319679394","shareBizCode":"20160311162_SECOND"}]', '$[0].merchantNo')),'') merchant_no union SELECT '20180531557' merchant_no;`) + tk.MustQuery(`select * from bug`).Sort().Check(testkit.Rows("20180531557", "20190430140319679394")) +} diff --git a/expression/builtin_json.go b/expression/builtin_json.go index 3869a1be8bcf7..3f3da54270745 100644 --- a/expression/builtin_json.go +++ b/expression/builtin_json.go @@ -16,6 +16,7 @@ package expression import ( "github.com/pingcap/errors" "github.com/pingcap/parser/ast" + "github.com/pingcap/parser/mysql" "github.com/pingcap/tidb/sessionctx" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/types/json" @@ -170,6 +171,7 @@ func (c *jsonUnquoteFunctionClass) getFunction(ctx sessionctx.Context, args []Ex return nil, errors.Trace(err) } bf := newBaseBuiltinFuncWithTp(ctx, args, types.ETString, types.ETJson) + bf.tp.Flen = mysql.MaxFieldVarCharLength DisableParseJSONFlag4Expr(args[0]) sig := &builtinJSONUnquoteSig{bf} sig.setPbCode(tipb.ScalarFuncSig_JsonUnquoteSig) diff --git a/expression/typeinfer_test.go b/expression/typeinfer_test.go index 62aaa2d7c7075..f1a624546af5f 100644 --- a/expression/typeinfer_test.go +++ b/expression/typeinfer_test.go @@ -1921,7 +1921,7 @@ func (s *testInferTypeSuite) createTestCase4JSONFuncs() []typeInferTestCase { return []typeInferTestCase{ {"json_type(c_json)", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 51, types.UnspecifiedLength}, // TODO: Flen of json_unquote doesn't follow MySQL now. - {"json_unquote(c_json)", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 0, types.UnspecifiedLength}, + {"json_unquote(c_json)", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, mysql.MaxFieldVarCharLength, types.UnspecifiedLength}, {"json_extract(c_json, '')", mysql.TypeJSON, charset.CharsetUTF8MB4, mysql.BinaryFlag, mysql.MaxBlobWidth, 0}, {"json_set(c_json, '', 0)", mysql.TypeJSON, charset.CharsetUTF8MB4, mysql.BinaryFlag, mysql.MaxBlobWidth, 0}, {"json_insert(c_json, '', 0)", mysql.TypeJSON, charset.CharsetUTF8MB4, mysql.BinaryFlag, mysql.MaxBlobWidth, 0},