Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I don't know why I am getting a syntax error. I have checked my query carefully many times and read up on mysql reference for load data infile and everything seems fine. Here is my query:

LOAD DATA LOCAL INFILE '/tmp/phpnm6Zek' IGNORE INTO TABLE loaddata_temp FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\r\n' IGNORE 1 LINES (@sku, @model, @option, @option_value, @required, @quantity, @subtract, @price, @points, @weight) SET sku=@sku, model=@model, option=@option, option_value=@option_value, required=@required, quantity=@quantity, subtract=@subtract, price=@price, points=@points, weight=@weight

This is the error that I am getting:

Notice: 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 'option=@option, option_value=@option_value, required=@required, quantity=@quanti' at line 1
Error No: 1064
LOAD DATA LOCAL INFILE '/tmp/phpO6k4u3' IGNORE INTO TABLE loaddata_temp FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\r\n' IGNORE 1 LINES (@sku, @model, @option, @option_value, @required, @quantity, @subtract, @price, @points, @weight) SET sku=@sku, model=@model, option=@option, option_value=@option_value, required=@required, quantity=@quantity, subtract=@subtract, price=@price, points=@points, weight=@weight
share|improve this question

1 Answer 1

up vote 1 down vote accepted

The word option is a reserved word : http://dev.mysql.com/doc/refman/5.6/en/reserved-words.html

You need to surround the word option with back quotes.

LOAD DATA LOCAL INFILE '/tmp/phpnm6Zek' IGNORE INTO TABLE loaddata_temp FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\r\n' IGNORE 1 LINES (@sku, @model, @option, @option_value, @required, @quantity, @subtract, @price, @points, @weight) SET sku=@sku, model=@model, `option`=@option, option_value=@option_value, required=@required, quantity=@quantity, subtract=@subtract, price=@price, points=@points, weight=@weight

Give it a Try !!!

share|improve this answer
    
Oh wow... thanks! That was indeed the problem. –  Sparctus Jan 31 at 19:59

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.