@@ -339,7 +339,7 @@ func (e *UpdateExec) updateRows(ctx context.Context) (int, error) {
339
339
return totalNumRows , nil
340
340
}
341
341
342
- func (* UpdateExec ) handleErr (colName model.CIStr , rowIdx int , err error ) error {
342
+ func (e * UpdateExec ) handleErr (colName model.CIStr , col * table. Column , rowIdx int , err error ) error {
343
343
if err == nil {
344
344
return nil
345
345
}
@@ -351,7 +351,10 @@ func (*UpdateExec) handleErr(colName model.CIStr, rowIdx int, err error) error {
351
351
if types .ErrOverflow .Equal (err ) {
352
352
return types .ErrWarnDataOutOfRange .GenWithStackByArgs (colName .O , rowIdx + 1 )
353
353
}
354
-
354
+ if types .ErrTruncatedWrongVal .Equal (err ) && col != nil && col .ColumnInfo != nil && col .ColumnInfo .GetType () == mysql .TypeTimestamp {
355
+ ec := e .Ctx ().GetSessionVars ().StmtCtx .ErrCtx ()
356
+ return errors .AddStack (ec .HandleErrorWithAlias (kv .ErrKeyExists , err , err ))
357
+ }
355
358
return err
356
359
}
357
360
@@ -364,15 +367,15 @@ func (e *UpdateExec) fastComposeNewRow(rowIdx int, oldRow []types.Datum, cols []
364
367
}
365
368
con := assign .Expr .(* expression.Constant )
366
369
val , err := con .Eval (e .Ctx ().GetExprCtx ().GetEvalCtx (), emptyRow )
367
- if err = e .handleErr (assign .ColName , rowIdx , err ); err != nil {
370
+ if err = e .handleErr (assign .ColName , cols [ assign . Col . Index ], rowIdx , err ); err != nil {
368
371
return nil , err
369
372
}
370
373
371
374
// info of `_tidb_rowid` column is nil.
372
375
// No need to cast `_tidb_rowid` column value.
373
376
if cols [assign .Col .Index ] != nil {
374
377
val , err = table .CastValue (e .Ctx (), val , cols [assign .Col .Index ].ColumnInfo , false , false )
375
- if err = e .handleErr (assign .ColName , rowIdx , err ); err != nil {
378
+ if err = e .handleErr (assign .ColName , cols [ assign . Col . Index ], rowIdx , err ); err != nil {
376
379
return nil , err
377
380
}
378
381
}
@@ -399,7 +402,7 @@ func (e *UpdateExec) composeNewRow(rowIdx int, oldRow []types.Datum, cols []*tab
399
402
// No need to cast `_tidb_rowid` column value.
400
403
if cols [assign .Col .Index ] != nil {
401
404
val , err = table .CastValue (e .Ctx (), val , cols [assign .Col .Index ].ColumnInfo , false , false )
402
- if err = e .handleErr (assign .ColName , rowIdx , err ); err != nil {
405
+ if err = e .handleErr (assign .ColName , cols [ assign . Col . Index ], rowIdx , err ); err != nil {
403
406
return nil , err
404
407
}
405
408
}
@@ -420,15 +423,15 @@ func (e *UpdateExec) composeGeneratedColumns(rowIdx int, newRowData []types.Datu
420
423
continue
421
424
}
422
425
val , err := assign .Expr .Eval (e .Ctx ().GetExprCtx ().GetEvalCtx (), e .evalBuffer .ToRow ())
423
- if err = e .handleErr (assign .ColName , rowIdx , err ); err != nil {
426
+ if err = e .handleErr (assign .ColName , cols [ assign . Col . Index ], rowIdx , err ); err != nil {
424
427
return nil , err
425
428
}
426
429
427
430
// info of `_tidb_rowid` column is nil.
428
431
// No need to cast `_tidb_rowid` column value.
429
432
if cols [assign .Col .Index ] != nil {
430
433
val , err = table .CastValue (e .Ctx (), val , cols [assign .Col .Index ].ColumnInfo , false , false )
431
- if err = e .handleErr (assign .ColName , rowIdx , err ); err != nil {
434
+ if err = e .handleErr (assign .ColName , cols [ assign . Col . Index ], rowIdx , err ); err != nil {
432
435
return nil , err
433
436
}
434
437
}
0 commit comments