Skip to content

Commit 9bf59f7

Browse files
authored
executor: fix INSERT IGNORE + STRICT Mode + DST transition. (#61440) (#62304)
close #61439
1 parent 773d726 commit 9bf59f7

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

pkg/executor/insert_common.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,8 @@ func (e *InsertValues) handleErr(col *table.Column, val *types.Datum, rowIdx int
325325
if col != nil && col.GetType() == mysql.TypeTimestamp &&
326326
types.ErrTimestampInDSTTransition.Equal(err) {
327327
newErr := exeerrors.ErrTruncateWrongInsertValue.FastGenByArgs(types.TypeStr(col.GetType()), val.GetString(), col.Name.O, rowIdx+1)
328-
if e.Ctx().GetSessionVars().SQLMode.HasStrictMode() {
328+
// IGNORE takes precedence over STRICT mode.
329+
if !e.ignoreErr && e.Ctx().GetSessionVars().SQLMode.HasStrictMode() {
329330
return newErr
330331
}
331332
// timestamp already adjusted to end of DST transition, convert error to warning

tests/integrationtest/r/executor/insert.result

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2380,3 +2380,22 @@ id ts mode
23802380
DROP TABLE t;
23812381
SET @@time_zone = @old_time_zone;
23822382
SET @@sql_mode = @old_sql_mode;
2383+
SET @old_time_zone = @@time_zone;
2384+
SET @@time_zone = 'Europe/Amsterdam';
2385+
SET @old_sql_mode = @@sql_mode;
2386+
create table t (ts timestamp);
2387+
set time_zone = 'Europe/Amsterdam';
2388+
set sql_mode = 'strict_trans_tables,no_zero_date,no_zero_in_date,error_for_division_by_zero';
2389+
insert into t values ('2025-03-30 02:00:00');
2390+
Error 1292 (22007): Incorrect timestamp value: '2025-03-30 02:00:00' for column 'ts' at row 1
2391+
select * from t;
2392+
ts
2393+
insert ignore into t values ('2025-03-30 02:00:00');
2394+
Level Code Message
2395+
Warning 1292 Incorrect timestamp value: '2025-03-30 02:00:00' for column 'ts' at row 1
2396+
select * from t;
2397+
ts
2398+
2025-03-30 03:00:00
2399+
DROP TABLE t;
2400+
SET @@time_zone = @old_time_zone;
2401+
SET @@sql_mode = @old_sql_mode;

tests/integrationtest/t/executor/insert.test

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1732,4 +1732,20 @@ SELECT * FROM t ORDER BY id;
17321732
DROP TABLE t;
17331733
SET @@time_zone = @old_time_zone;
17341734
SET @@sql_mode = @old_sql_mode;
1735+
1736+
# Testing INSERT IGNORE with STRICT mode, #61439
1737+
SET @old_time_zone = @@time_zone;
1738+
SET @@time_zone = 'Europe/Amsterdam';
1739+
SET @old_sql_mode = @@sql_mode;
1740+
create table t (ts timestamp);
1741+
set time_zone = 'Europe/Amsterdam';
1742+
set sql_mode = 'strict_trans_tables,no_zero_date,no_zero_in_date,error_for_division_by_zero';
1743+
--error 1292
1744+
insert into t values ('2025-03-30 02:00:00');
1745+
select * from t;
1746+
insert ignore into t values ('2025-03-30 02:00:00');
1747+
select * from t;
1748+
DROP TABLE t;
1749+
SET @@time_zone = @old_time_zone;
1750+
SET @@sql_mode = @old_sql_mode;
17351751
--disable_warnings

0 commit comments

Comments
 (0)