diff --git a/infoschema/tables.go b/infoschema/tables.go index bd2bda00cbd09..894129efbc157 100644 --- a/infoschema/tables.go +++ b/infoschema/tables.go @@ -833,7 +833,11 @@ func dataForColumnsInTable(schema *model.DBInfo, tbl *model.TableInfo) [][]types datetimePrecision = decimal } else if types.IsTypeNumeric(col.Tp) { numericPrecision = colLen - numericScale = decimal + if col.Tp != mysql.TypeFloat && col.Tp != mysql.TypeDouble { + numericScale = decimal + } else if decimal != -1 { + numericScale = decimal + } } columnType := col.FieldType.InfoSchemaStr() columnDesc := table.NewColDesc(table.ToColumn(col)) diff --git a/infoschema/tables_test.go b/infoschema/tables_test.go index 82f08876f5982..c88c370f39ea0 100644 --- a/infoschema/tables_test.go +++ b/infoschema/tables_test.go @@ -40,6 +40,7 @@ func (s *testSuite) TestInfoschemaFielValue(c *C) { tk.MustExec("create table numschema(i int(2), f float(4,2), d decimal(4,3))") tk.MustExec("create table timeschema(d date, dt datetime(3), ts timestamp(3), t time(4), y year(4))") tk.MustExec("create table strschema(c char(3), c2 varchar(3), b blob(3), t text(3))") + tk.MustExec("create table floatschema(a float, b double(7, 3))") tk.MustQuery("select CHARACTER_MAXIMUM_LENGTH,CHARACTER_OCTET_LENGTH,NUMERIC_PRECISION,NUMERIC_SCALE,DATETIME_PRECISION from information_schema.COLUMNS where table_name='numschema'"). Check(testkit.Rows(" 2 0 ", " 4 2 ", " 4 3 ")) // FIXME: for mysql first one will be " 10 0 " @@ -47,6 +48,8 @@ func (s *testSuite) TestInfoschemaFielValue(c *C) { Check(testkit.Rows(" ", " 3", " 3", " 4", " ")) tk.MustQuery("select CHARACTER_MAXIMUM_LENGTH,CHARACTER_OCTET_LENGTH,NUMERIC_PRECISION,NUMERIC_SCALE,DATETIME_PRECISION from information_schema.COLUMNS where table_name='strschema'"). Check(testkit.Rows("3 3 ", "3 3 ", "3 3 ", "3 3 ")) // FIXME: for mysql last two will be "255 255 ", "255 255 " + tk.MustQuery("select NUMERIC_SCALE from information_schema.COLUMNS where table_name='floatschema'"). + Check(testkit.Rows("", "3")) } func (s *testSuite) TestDataForTableRowsCountField(c *C) {