Skip to content

Commit

Permalink
executor: generated column make overflow error as warning when no str…
Browse files Browse the repository at this point in the history
…ict sql mode (pingcap#21879)

Signed-off-by: lzmhhh123 <[email protected]>
  • Loading branch information
lzmhhh123 authored Dec 21, 2020
1 parent e573ed6 commit f9092ad
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion executor/insert_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ func (e *InsertValues) fillRow(ctx context.Context, row []types.Datum, hasValue
for i, gCol := range gCols {
colIdx := gCol.ColumnInfo.Offset
val, err := e.GenExprs[i].Eval(chunk.MutRowFromDatums(row).ToRow())
if e.handleErr(gCol, &val, 0, err) != nil {
if e.ctx.GetSessionVars().StmtCtx.HandleTruncate(err) != nil {
return nil, err
}
row[colIdx], err = table.CastValue(e.ctx, val, gCol.ToInfo(), false, false)
Expand Down
8 changes: 8 additions & 0 deletions executor/write_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1076,6 +1076,14 @@ func (s *testSuite2) TestGeneratedColumnForInsert(c *C) {
tk.MustExec(`insert into t (k) values (1), (2)`)
tk.MustExec(`replace into t (k) values (1), (2)`)
tk.MustQuery(`select * from t`).Check(testkit.Rows("2 3 1", "3 4 2"))

// For issue 14340
tk.MustExec(`drop table if exists t1`)
tk.MustExec(`create table t1(f1 json, f2 real as (cast(f1 as decimal(2,1))))`)
tk.MustGetErrMsg(`INSERT INTO t1 (f1) VALUES (CAST(1000 AS JSON))`, "[types:1690]DECIMAL value is out of range in '(2, 1)'")
tk.MustExec(`set @@sql_mode = ''`)
tk.MustExec(`INSERT INTO t1 (f1) VALUES (CAST(1000 AS JSON))`)
tk.MustQuery(`select * from t1`).Check(testkit.Rows("1000 9.9"))
}

func (s *testSuite4) TestPartitionedTableReplace(c *C) {
Expand Down

0 comments on commit f9092ad

Please sign in to comment.