File tree Expand file tree Collapse file tree 2 files changed +17
-8
lines changed Expand file tree Collapse file tree 2 files changed +17
-8
lines changed Original file line number Diff line number Diff line change @@ -958,6 +958,14 @@ func TestGetDefaultValueOfColumn(t *testing.T) {
958
958
959
959
tk .MustQuery ("select * from t1" ).Check (testkit .RowsWithSep ("|" , "" +
960
960
"1962-03-03 1962-03-03 00:00:00 12:23:23 2020-10-13 2020-03-27" ))
961
+
962
+ tk .MustExec ("drop table if exists t;" )
963
+ tk .MustExec ("create table t(a decimal(0,0), b decimal(0));" )
964
+ tk .MustQuery ("show create table t;" ).Check (testkit .RowsWithSep ("|" , "" +
965
+ "t CREATE TABLE `t` (\n " +
966
+ " `a` decimal(10,0) DEFAULT NULL,\n " +
967
+ " `b` decimal(10,0) DEFAULT NULL\n " +
968
+ ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin" ))
961
969
}
962
970
963
971
func TestIssue39080 (t * testing.T ) {
Original file line number Diff line number Diff line change @@ -1417,21 +1417,22 @@ func checkColumn(colDef *ast.ColumnDef) error {
1417
1417
}
1418
1418
}
1419
1419
case mysql .TypeNewDecimal :
1420
- if tp .GetDecimal () > mysql .MaxDecimalScale {
1421
- return types .ErrTooBigScale .GenWithStackByArgs (tp .GetDecimal (), colDef .Name .Name .O , mysql .MaxDecimalScale )
1420
+ tpFlen := tp .GetFlen ()
1421
+ tpDecimal := tp .GetDecimal ()
1422
+ if tpDecimal > mysql .MaxDecimalScale {
1423
+ return types .ErrTooBigScale .GenWithStackByArgs (tpDecimal , colDef .Name .Name .O , mysql .MaxDecimalScale )
1422
1424
}
1423
-
1424
- if tp .GetFlen () > mysql .MaxDecimalWidth {
1425
- return types .ErrTooBigPrecision .GenWithStackByArgs (tp .GetFlen (), colDef .Name .Name .O , mysql .MaxDecimalWidth )
1425
+ if tpFlen > mysql .MaxDecimalWidth {
1426
+ return types .ErrTooBigPrecision .GenWithStackByArgs (tpFlen , colDef .Name .Name .O , mysql .MaxDecimalWidth )
1426
1427
}
1427
-
1428
- if tp .GetFlen () < tp .GetDecimal () {
1428
+ if tpFlen < tpDecimal {
1429
1429
return types .ErrMBiggerThanD .GenWithStackByArgs (colDef .Name .Name .O )
1430
1430
}
1431
1431
// If decimal and flen all equals 0, just set flen to default value.
1432
- if tp . GetDecimal () == 0 && tp . GetFlen () == 0 {
1432
+ if tpFlen == 0 && ( tpDecimal == 0 || tpDecimal == types . UnspecifiedLength ) {
1433
1433
defaultFlen , _ := mysql .GetDefaultFieldLengthAndDecimal (mysql .TypeNewDecimal )
1434
1434
tp .SetFlen (defaultFlen )
1435
+ tp .SetDecimal (0 )
1435
1436
}
1436
1437
case mysql .TypeBit :
1437
1438
if tp .GetFlen () <= 0 {
You can’t perform that action at this time.
0 commit comments