Avatar of MFredin
MFredinFlag for United States of America

asked on 

MySQL partitioning trouble

I'm trying to partition a MySQL 5.5 MyISAM table but getting an error.  Partitioning by state.  phy_st (varchar) is a column mytable and the values are the state abbreviations.  From what I've read, this should work.  What am I missing here?

ALTER TABLE mytable
PARTITION BY LIST COLUMN(phy_st)
    PARTITION p1 VALUES IN('NY','FL','GA'),
    PARTITION p2 VALUES IN('TX','MI','CA'),
    PARTITION p3 VALUES IN('MN','IN','IL'),    
    PARTITION p4 VALUES IN('WI','NJ','AL'),
    PARTITION p5 VALUES IN('OH','KY','NC'),
    PARTITION p6 VALUES IN('MD','TN','CO'),    
    PARTITION p7 VALUES IN('MO','IA','NE'),
    PARTITION p8 VALUES IN('MA','OK','OR'),
    PARTITION p9 VALUES IN('VA','SC','AZ'),    
    PARTITION p10 VALUES IN('PA','WA','UT'),    
    PARTITION p11 VALUES IN('LA','KS','MS'),
    PARTITION p12 VALUES IN('WV','AR','CT'),
    PARTITION p13 VALUES IN('ME','ID','NM'),    
    PARTITION p14 VALUES IN('ON','NH','MT'),
    PARTITION p15 VALUES IN('SD','RI','WY'),
    PARTITION p16 VALUES IN('QC','NV','ND'),
    PARTITION p17 VALUES IN('DE','BN','VT'),  
    PARTITION p18 VALUES IN('TA','BC','AB'),
    PARTITION p19 VALUES IN('CI','MB','NB'),
    PARTITION p20 VALUES IN('NL','SK','SO'),    
    PARTITION p21 VALUES IN('DC','SI','CH'),
    PARTITION p22 VALUES IN('MX','NS','JA'),
    PARTITION p23 VALUES IN('GJ','BS','DF'),    
    PARTITION p24 VALUES IN('MC','VC','DG'),
    PARTITION p25 VALUES IN('PE','SL','AG'),
    PARTITION p26 VALUES IN('YT','QE','HD','PU','TL'),    
    PARTITION p27 VALUES IN('ZA','CL','GU','CP','MR','NA'),
    PARTITION p28 VALUES IN('MP','TB','AS','OA','GE','CS','YU','NT','QI')
);


Error:

[Err] 1064 - 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 'COLUMN(phy_st)

    PARTITION p1 VALUES IN('NY','FL','GA'),
    PARTITION p2 ' at line 2
MySQL Server

Avatar of undefined
Last Comment
Guy Hengel [angelIII / a3]
SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of MFredin
MFredin
Flag of United States of America image

ASKER

Hi angelIII,

I tried:
ALTER TABLE fmcsa
PARTITION BY LIST(phy_st)
    PARTITION p1 VALUES IN('NY','FL','GA'),
    PARTITION p2 VALUES IN('TX','MI','CA'),
    PARTITION p3 VALUES IN('MN','IN','IL'),  
    PARTITION p28 VALUES IN('MP','TB','AS','OA','GE','CS','YU','NT','QI')
);

and got the same error
Avatar of MFredin
MFredin
Flag of United States of America image

ASKER

sorry... missed a "(" in there.  Fixed that and here's the new error:

[Err] 1064 - VALUES value must be of same type as partition function near ''FL','GA'),
    PARTITION p2 VALUES IN('TX','MI','CA'),
    PARTITION p3 VALUE' at line 4
Avatar of MFredin
MFredin
Flag of United States of America image

ASKER

another important update... I double checked my version and I was actually on 5.1.  I upgraded to 5.5 and getting this error:


VALUES value for partition 'p1' must have type INT

I was pretty sure with 5.5 you could partition on varchar
Avatar of rubene
rubene
Flag of Netherlands image

Hi,

I think instead of using LIST partitioning you should use COLUMN partitioning, see: http://dev.mysql.com/doc/refman/5.5/en/partitioning-columns.html
Because with LIST partitioning only numeric values are allowed.
Avatar of MFredin
MFredin
Flag of United States of America image

ASKER

I tried:

ALTER TABLE fmcsa
PARTITION BY LIST COLUMNS(phy_st) (
    PARTITION p1 VALUES IN( 'NY','FL','GA'),
    PARTITION p2 VALUES IN( 'TX','MI','CA'),....

but got

[Err] 1503 - A PRIMARY KEY must include all columns in the table's partitioning function
ASKER CERTIFIED SOLUTION
Avatar of rubene
rubene
Flag of Netherlands image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
http://dev.mysql.com/doc/refman/5.1/en/partitioning-list.html
This is done by using PARTITION BY LIST(expr) where expr is a column value or an expression based on a column value and returning an integer value
MySQL Server
MySQL Server

MySQL is an open source, relational database management system that runs as a server providing multi-user access to a number of databases. Acquired by Oracle in 2009, it is frequently used in combination with PHP installations, powering most of the WordPress installations.

49K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo