From f15985578a1841241970129fb85175213a9df772 Mon Sep 17 00:00:00 2001 From: Lloyd-Pottiger <60744015+Lloyd-Pottiger@users.noreply.github.com> Date: Thu, 21 Mar 2024 19:57:43 +0800 Subject: [PATCH] Schema: replace invalid default value to zero value under not strict sql mode (#8850) close pingcap/tiflash#8803 --- .../variables/set_sql_mode_ansi.test | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 tests/fullstack-test2/variables/set_sql_mode_ansi.test diff --git a/tests/fullstack-test2/variables/set_sql_mode_ansi.test b/tests/fullstack-test2/variables/set_sql_mode_ansi.test new file mode 100644 index 00000000000..40e398293a6 --- /dev/null +++ b/tests/fullstack-test2/variables/set_sql_mode_ansi.test @@ -0,0 +1,51 @@ +# Copyright 2024 PingCAP, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# use an empty string as the default value for decimal column +mysql> set sql_mode='ansi'; CREATE TABLE test.t (id int, i int default '1.1', f float default 'a', d decimal(10,2) default 'b', y year default 'f'); + +mysql> set sql_mode='ansi'; insert into test.t (id) values (1),(2),(3),(4); +mysql> alter table test.t set tiflash replica 1; + +func> wait_table test t + +mysql> set sql_mode='ansi'; insert into test.t (id) values (5),(6),(7),(8); +mysql> set sql_mode='ansi'; set session tidb_isolation_read_engines='tikv'; select * from test.t; ++------+------+------+------+------+ +| id | i | f | d | y | ++------+------+------+------+------+ +| 1 | 1 | 0 | 0.00 | 0000 | +| 2 | 1 | 0 | 0.00 | 0000 | +| 3 | 1 | 0 | 0.00 | 0000 | +| 4 | 1 | 0 | 0.00 | 0000 | +| 5 | 1 | 0 | 0.00 | 0000 | +| 6 | 1 | 0 | 0.00 | 0000 | +| 7 | 1 | 0 | 0.00 | 0000 | +| 8 | 1 | 0 | 0.00 | 0000 | ++------+------+------+------+------+ +mysql> set sql_mode='ansi'; set session tidb_isolation_read_engines='tiflash'; select * from test.t; ++------+------+------+------+------+ +| id | i | f | d | y | ++------+------+------+------+------+ +| 1 | 1 | 0 | 0.00 | 0000 | +| 2 | 1 | 0 | 0.00 | 0000 | +| 3 | 1 | 0 | 0.00 | 0000 | +| 4 | 1 | 0 | 0.00 | 0000 | +| 5 | 1 | 0 | 0.00 | 0000 | +| 6 | 1 | 0 | 0.00 | 0000 | +| 7 | 1 | 0 | 0.00 | 0000 | +| 8 | 1 | 0 | 0.00 | 0000 | ++------+------+------+------+------+ + +mysql> drop table test.t;