gpt4 book ai didi

mysql按天分区

转载 作者:太空宇宙 更新时间:2023-11-03 11:08:18 26 4
gpt4 key购买 nike

您好,我想为我的表添加分区。表格多媒体包含最近 7 天的记录所以我想创建 7 个分区,一个分区 - 一天所以尝试执行此迁移:

def up
execute "ALTER TABLE multimedia
partition by range (to_days(created_at))
(
PARTITION p0 VALUES LESS THAN (to_days(#{Time.now - (7 * 24 * 60 * 60)})),
PARTITION p1 VALUES LESS THAN (to_days(#{Time.now - (6 * 24 * 60 * 60)})),
PARTITION p2 VALUES LESS THAN (to_days(#{Time.now - (5 * 24 * 60 * 60)})),
PARTITION p3 VALUES LESS THAN (to_days(#{Time.now - (4 * 24 * 60 * 60)})),
PARTITION p4 VALUES LESS THAN (to_days(#{Time.now - (3 * 24 * 60 * 60)})),
PARTITION p5 VALUES LESS THAN (to_days(#{Time.now - (2 * 24 * 60 * 60)})),
PARTITION p6 VALUES LESS THAN (to_days(#{Time.now - (1 * 24 * 60 * 60)})),
PARTITION p7 VALUES LESS THAN (to_days(#{Time.now - (0 * 24 * 60 * 60)})),
PARTITION p8 VALUES LESS THAN MAXVALUE
);"
end

迁移的结果是以下错误:

An error has occurred, all later migrations canceled:

Mysql2::Error: 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
'11:09:43 +0200)),
PARTITION p1 VALUES LESS THAN (to_days(2012-04-18 11:0' at line 4: ALTER TABLE multimedia
partition by range (to_days(created_at))
(

== AddPartitionToMultimedia: migrating =======================================
--
execute("ALTER TABLE multimedia \n
partition by range (to_days(created_at))\n
( \n
PARTITION p0 VALUES LESS THAN (to_days(2012-04-17 11:09:43 +0200)),\n
PARTITION p1 VALUES LESS THAN (to_days(2012-04-18 11:09:43 +0200)),\n
PARTITION p2 VALUES LESS THAN (to_days(2012-04-19 11:09:43 +0200)),\n
PARTITION p3 VALUES LESS THAN (to_days(2012-04-20 11:09:43 +0200)),\n
PARTITION p4 VALUES LESS THAN (to_days(2012-04-21 11:09:43 +0200)),\n
PARTITION p5 VALUES LESS THAN (to_days(2012-04-22 11:09:43 +0200)),\n
PARTITION p6 VALUES LESS THAN (to_days(2012-04-23 11:09:43 +0200)),\n
PARTITION p7 VALUES LESS THAN (to_days(2012-04-24 11:09:43 +0200)),\n
PARTITION p8 VALUES LESS THAN MAXVALUE \n
);")

最佳答案

to_days 函数有错误。您需要确保传递给 to_days 的值是字符串类型。类似于下面的代码:

to_days('2012-04-17 11:09:43 +0200')
^ ^
| |

关于mysql按天分区,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10295101/

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