2012-09-05 39 views
0

我試圖通過mysql表中的時間戳進行分區。但它返回一個錯誤。如果我嘗試使用NOW()也會返回錯誤。如何解決此錯誤並使用時間戳數據類型進行分區?在Mysql的範圍分區中使用時間戳

CREATE TABLE tblemployeepunch (
    fld_id int(11) NOT NULL AUTO_INCREMENT, 
    fld_date Varchar(15) DEFAULT NULL, 
    fld_rawpunchdate varchar(25) DEFAULT NULL, 
    fld_rawpunchtime varchar(25) DEFAULT NULL, 
    fld_cardno varchar(50) DEFAULT NULL, 
    fld_reasoncard varchar(20) DEFAULT NULL, 
    fld_mode varchar(20) DEFAULT NULL, 
    fld_punchdatetime varchar(50) DEFAULT NULL, 
    fld_crtdate TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, 
    UNIQUE KEY fld_id (fld_id,fld_crtdate), 
    KEY in_timesheet (fld_cardno,fld_punchdatetime,fld_mode,fld_rawpunchtime), 
    KEY in_emppunch (fld_cardno,fld_rawpunchdate,fld_punchdatetime) 
) 
    PARTITION BY RANGE (fld_crtdate) 
    (PARTITION p_Sep12 VALUES LESS THAN (TO_TIMESTAMP('2012-10-01 00:00:00')), 
    PARTITION p_Oct12 VALUES LESS THAN (TO_TIMESTAMP('2012-11-01 00:00:00')), 
    PARTITION p_Nov12 VALUES LESS THAN (TO_TIMESTAMP('2012-12-01 00:00:00')), 
    PARTITION p_Max VALUES LESS THAN MAXVALUE); 
+0

什麼是你所得到的 – Satya

+0

ERR'TO_TIMESTAMP'不是MySQL的功能,這是甲骨文/ PostgreSQL的。 –

+0

@Sathya錯誤代碼:1064.不允許在(子)分區函數中使用常量,隨機或與時區相關的表達式 – Dhileepan

回答

1

這是解決此問題的正確查詢。使用UNIX_TIMESTAMP

 CREATE TABLE tblemployeepunch (
     fld_id int(11) NOT NULL AUTO_INCREMENT, 
     fld_date Varchar(15) DEFAULT NULL, 
     fld_rawpunchdate varchar(25) DEFAULT NULL, 
     fld_rawpunchtime varchar(25) DEFAULT NULL, 
     fld_cardno varchar(50) DEFAULT NULL, 
     fld_reasoncard varchar(20) DEFAULT NULL, 
     fld_mode varchar(20) DEFAULT NULL, 
     fld_punchdatetime varchar(50) DEFAULT NULL, 
     fld_crtdate TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, 
     UNIQUE KEY fld_id (fld_id,fld_crtdate), 
     KEY in_timesheet (fld_cardno,fld_punchdatetime,fld_mode,fld_rawpunchtime), 
     KEY in_emppunch (fld_cardno,fld_rawpunchdate,fld_punchdatetime) 
    ) 
    PARTITION BY RANGE (UNIX_TIMESTAMP(fld_crtdate)) 
    (PARTITION p_Sep12 VALUES LESS THAN (UNIX_TIMESTAMP('2012-10-01 00:00:00')), 
    PARTITION p_Oct12 VALUES LESS THAN (UNIX_TIMESTAMP('2012-11-01 00:00:00')), 
    PARTITION p_Nov12 VALUES LESS THAN (UNIX_TIMESTAMP('2012-12-01 00:00:00')), 
    PARTITION p_Max VALUES LESS THAN MAXVALUE); 
+0

你知道如果查詢使用分區清理,如果我使用datetime和date2之間的mytimestamp? –