MySQL Forums
Forum List  »  Partitioning

ERROR 1564 on YEAR() function
Posted by: Stefan Reimers
Date: December 07, 2008 08:50AM

Hey,

I am stuck on an "ERROR 1564: This partition function is not allowed" executing the following statement. Perhaps someone has an idea how to fix it:

CREATE TABLE fact_something (id INT, purchased DATE)
PARTITION BY RANGE( YEAR(purchased) ) (
PARTITION p2006 VALUES LESS THAN (2006),
PARTITION p2007 VALUES LESS THAN (2007),
PARTITION p2008 VALUES LESS THAN MAXVALUE
);

DELIMITER //
CREATE DEFINER=root EVENT
yearly_partition
ON SCHEDULE
EVERY 1 YEAR
STARTS '2008-12-31 23:30:00'
ON COMPLETION PRESERVE
DO
BEGIN
DECLARE pNameOld CHAR(5) DEFAULT CONCAT('p',YEAR(CURRENT_DATE));
DECLARE pNameNew CHAR(5) DEFAULT CONCAT('p',YEAR(CURRENT_DATE)+1);
ALTER TABLE fact_something REORGANIZE PARTITION pNameOld INTO (PARTITION pNameOld VALUES LESS THAN (YEAR(CURENT_DATE)), PARTITION pNameNew VALUES LESS THAN MAXVALUE);
END//
DELIMITER ;

The MAXVALUE is initially chosen for mistyped values since the partition must only contain records out of 2008. Checks and fixes are run on application level.

The problems cause seems to be the YEAR(CURRENT_DATE) in the ALTER statement. I at first tried to declare another variable like
DECLARE pRangeOld INT DEFAULT YEAR(CURRENT_DATE);
and used it in the ALTER - which doesn't work. At last I fixed the value to 2008 so that my statement changed to that one:
...
ALTER TABLE fact_something REORGANIZE PARTITION pNameOld INTO (PARTITION pNameOld VALUES LESS THAN (2008), PARTITION pNameNew VALUES LESS THAN MAXVALUE);
...
That one works but is not what I wanted in a recurring event.

Can anyone help?

Thanks
Stefan

Options: ReplyQuote


Subject
Views
Written By
Posted
ERROR 1564 on YEAR() function
9172
December 07, 2008 08:50AM
4067
December 11, 2008 08:24AM
3574
December 27, 2008 06:05AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.