MySQL PARTITION BY month automatically

ALTER TABLE t1 PARTITION BY RANGE(transaction_date)(
PARTITION JAN VALUES LESS THAN (UNIX_TIMESTAMP('2013-02-01')),
PARTITION FEB VALUES LESS THAN (UNIX_TIMESTAMP('2013-03-01')),
PARTITION MAR VALUES LESS THAN (UNIX_TIMESTAMP('2013-04-01')),
PARTITION APR VALUES LESS THAN (UNIX_TIMESTAMP('2013-05-01')),
PARTITION MAY VALUES LESS THAN (UNIX_TIMESTAMP('2013-06-01')),
PARTITION JUN VALUES LESS THAN (UNIX_TIMESTAMP('2013-07-01')),
PARTITION JUL VALUES LESS THAN (UNIX_TIMESTAMP('2013-08-01')),
PARTITION AUG VALUES LESS THAN (UNIX_TIMESTAMP('2013-09-01')),
PARTITION SEP VALUES LESS THAN (UNIX_TIMESTAMP('2013-10-01')),
PARTITION `OCT` VALUES LESS THAN (UNIX_TIMESTAMP('2013-11-01')),
PARTITION NOV VALUES LESS THAN (UNIX_TIMESTAMP('2013-12-01')),
PARTITION `DEC` VALUES LESS THAN (UNIX_TIMESTAMP('2014-01-01'))
);

4
1
N. Gladkov 100 points

                                    ALTER TABLE t1 
PARTITION BY RANGE( MONTH(FROM_UNIXTIME(transaction_date) )
SUBPARTITION BY HASH( DAY(FROM_UNIXTIME(transaction_date)) )
SUBPARTITIONS 31 (
    PARTITION p0 VALUES LESS THAN (2),
    PARTITION p1 VALUES LESS THAN (3),
    PARTITION p2 VALUES LESS THAN (4),
    PARTITION p3 VALUES LESS THAN (5),
    PARTITION p4 VALUES LESS THAN (6),
    PARTITION p5 VALUES LESS THAN (7),
    PARTITION p6 VALUES LESS THAN (8),
    PARTITION p7 VALUES LESS THAN (9),
    PARTITION p8 VALUES LESS THAN (10),
    PARTITION p9 VALUES LESS THAN (11),
    PARTITION p10 VALUES LESS THAN (12),
    PARTITION p11 VALUES LESS THAN MAXVALUE
);

4 (1 Votes)
0
Are there any code examples left?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source