gpt4 book ai didi

MySQL 按范围分区 - 语句中出现错误?

转载 作者:行者123 更新时间:2023-11-29 12:17:05 24 4
gpt4 key购买 nike

我尝试通过添加分区来更改现有表,但出现 SQL 错误,尽管它看起来像文档所说的那样。

希望有人能指出我的错误。

表orders有一个名为date_order_start的字段,它是DATE,因此它没有时间信息。该字段有一个索引。该索引不是唯一的,也不是另一个唯一索引的一部分。

我想使用以下语句对表进行分区:

ALTER TABLE orders
PARTITION BY RANGE (date_order_start) (
startpoint VALUES LESS THAN (0),
from20140701 VALUES LESS THAN ('2014-07-01'),
from20140801 VALUES LESS THAN ('2014-08-01'),
from20140901 VALUES LESS THAN ('2014-09-01'),
future VALUES LESS THAN MAXVALUE
);

错误....

在我尝试这个之前:

ALTER TABLE orders
PARTITION BY RANGE (TO_DAYS(date_order_start)) (
startpoint VALUES LESS THAN (0),
from20140701 VALUES LESS THAN (TO_DAYS('2014-07-01')),
from20140801 VALUES LESS THAN (TO_DAYS('2014-08-01')),
from20140901 VALUES LESS THAN (TO_DAYS('2014-09-01')),
future VALUES LESS THAN MAXVALUE
);

但也出现错误:

**Error Code: 1064**. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'from20140701 VALUES LESS THAN ('2014-07-01'), from20140801 VALUES LESS T' at line 4

嗯......这没有帮助。

有人能发现错误吗?

没有起始点声明的变化也不起作用。我想也许 (0) 是问题所在。

我使用这些页面来获取信息:

http://dev.mysql.com/tech-resources/articles/mysql_55_partitioning.html http://dev.mysql.com/doc/refman/5.5/en/alter-table-partition-operations.html

最佳答案

我想知道您是否只是缺少分区关键字:

ALTER TABLE 订单
按范围分区 (date_order_start) (
分区起点值小于 (0),
来自 20140701 的分区值小于 ('2014-07-01'),
来自 20140801 的分区值小于 ('2014-08-01'),
来自 20140901 的分区值小于 ('2014-09-01'),
对小于 MAXVALUE 的 future 值进行分区
);

此外,VALUES LESS THAN (0) 部分真的有必要吗?

关于MySQL 按范围分区 - 语句中出现错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29632346/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com