From a472ca6279701af5e36befd53d5297a827d3f138 Mon Sep 17 00:00:00 2001 From: pingcap-github-bot Date: Wed, 22 Apr 2020 16:22:49 +0800 Subject: [PATCH] ddl: create partition table fail with strconv.ParseInt invalid syntax (#16436) (#16499) --- 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 86aa06f368718..77558653e2b3d 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 t34 (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 t34 (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 0ee90343a188c..a012862e83363 100644 --- a/ddl/partition.go +++ b/ddl/partition.go @@ -325,7 +325,7 @@ func checkPartitionFuncType(ctx sessionctx.Context, s *ast.CreateTableStmt, tblI func checkCreatePartitionValue(ctx sessionctx.Context, tblInfo *model.TableInfo) error { pi := tblInfo.Partition defs := pi.Definitions - if len(defs) <= 1 { + if len(defs) == 0 { return nil }