0

こんにちは、テーブルにパーティションを追加したいと思います。テーブルマルチメディアコンタニンは過去7日間を記録しているので、7つのパーティション、1つのパーティションを作成したいので、ある日、この移行を実行してみてください。

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      
);")
4

1 に答える 1

4

関数にエラーがありますto_daysto_days渡される値が文字列のタイプであることを確認する必要があります。以下のコードのようなもの:

to_days('2012-04-17 11:09:43 +0200')
        ^                         ^
        |                         |
于 2012-04-24T09:52:31.000 に答える