From 0c67b23ec51c19383311c03db3213a0ed17fb79e Mon Sep 17 00:00:00 2001 From: pingcap-github-bot Date: Fri, 17 Apr 2020 12:00:48 +0800 Subject: [PATCH] ddl: create partition table fail with strconv.ParseInt invalid syntax (#16436) (#16498) --- ddl/db_partition_test.go | 17 +++++++++++++++++ ddl/partition.go | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/ddl/db_partition_test.go b/ddl/db_partition_test.go index 7d54bbb3d489a..042dd69f458a4 100644 --- a/ddl/db_partition_test.go +++ b/ddl/db_partition_test.go @@ -261,6 +261,23 @@ func (s *testIntegrationSuite9) TestCreateTableWithPartition(c *C) { PARTITION p2 VALUES LESS THAN (2000), PARTITION p3 VALUES LESS THAN (2005) );`, tmysql.ErrBadField) + + // Fix a timezone dependent check bug introduced in https://github.com/pingcap/tidb/pull/10655 + tk.MustExec(`create table t34 (dt timestamp(3)) partition by range (floor(unix_timestamp(dt))) ( + partition p0 values less than (unix_timestamp('2020-04-04 00:00:00')), + partition p1 values less than (unix_timestamp('2020-04-05 00:00:00')));`) + + tk.MustGetErrCode(`create table t35 (dt timestamp(3)) partition by range (unix_timestamp(date(dt))) ( + partition p0 values less than (unix_timestamp('2020-04-04 00:00:00')), + partition p1 values less than (unix_timestamp('2020-04-05 00:00:00')));`, tmysql.ErrWrongExprInPartitionFunc) + + tk.MustGetErrCode(`create table t35 (dt datetime) partition by range (unix_timestamp(dt)) ( + partition p0 values less than (unix_timestamp('2020-04-04 00:00:00')), + partition p1 values less than (unix_timestamp('2020-04-05 00:00:00')));`, tmysql.ErrWrongExprInPartitionFunc) + + // Fix https://github.com/pingcap/tidb/issues/16333 + tk.MustExec(`create table t35 (dt timestamp) partition by range (unix_timestamp(dt)) +(partition p0 values less than (unix_timestamp('2020-04-15 00:00:00')));`) } func (s *testIntegrationSuite7) TestCreateTableWithHashPartition(c *C) { diff --git a/ddl/partition.go b/ddl/partition.go index 6adb48937c90a..f261c14d62557 100644 --- a/ddl/partition.go +++ b/ddl/partition.go @@ -330,7 +330,7 @@ func checkPartitionFuncType(ctx sessionctx.Context, s *ast.CreateTableStmt, cols // Side effect: it may simplify the partition range definition from a constant expression to an integer. func checkCreatePartitionValue(ctx sessionctx.Context, tblInfo *model.TableInfo, pi *model.PartitionInfo, cols []*table.Column) error { defs := pi.Definitions - if len(defs) <= 1 { + if len(defs) == 0 { return nil }