分区MySQL表列

时间:2013-07-04 13:28:05

标签: mysql partitioning

我想在MySQL中使用如下所示的分区创建表

CREATE TABLE `ccd` (
  `Created Month` varchar(255) DEFAULT NULL,
  `Created` varchar(255) DEFAULT NULL,
  `Employee Organization Name` varchar(255) DEFAULT NULL,
  `Employee Login` varchar(255) DEFAULT NULL,
  `Service Request #` varchar(255) DEFAULT NULL,
  `Status` varchar(255) DEFAULT NULL,
  `Description` longtext)
ENGINE=MyISAM DEFAULT CHARSET=latin1

PARTITION BY RANGE (SUBSTRING(`Created Month`,1,4)  )

(PARTITION sp0 VALUES LESS THAN ('2010') ENGINE = MyISAM,

 PARTITION sp1 VALUES LESS THAN   ('2012' ) ENGINE = MyISAM,

 PARTITION sp2 VALUES LESS THAN ('2014' ) ENGINE = MyISAM

);

在表格中,Created Month列的值为

Created Month
2011 / 02
2011 / 06
2012 / 02
2013 / 01
2013 / 02
2013 / 05
2013 / 05

当我尝试运行该语句时,我收到错误消息,如

ERROR: This partition function is not allowed
Error Code: 1564

任何人都告诉我,我在哪里弄错了??

1 个答案:

答案 0 :(得分:2)

并非所有函数都可以在数据分区规则中使用,您可以想象SUBSTRING就是其中之一。

List of allowed functions

解决方案:

Created Monthvarchar更改为date,然后使用:
    - PARTITION BY RANGE (MONTH(Created Month) )