0

I'm trying to import selected columns from a CSV to the DB using:

LOAD DATA LOCAL INFILE 'local/path/to/file.csv' 
INTO TABLE product 
(ItemName,ItemShortDescription,RetailPrice,Brand,Category,@PRICE_1,@PRICE_2,@PRICE_3,Weight,Length,Width,Height) 
FIELDS TERMINATED BY '|' 
ESCAPED BY '"'
LINES TERMINATED BY '\n'  

.. so skipping the 3 columns from the CSV (PRICE_1,PRICE_2,PRICE_3)

product table:

CREATE TABLE `product` (
  `pid` int(255) NOT NULL AUTO_INCREMENT,
  `ItemName` varchar(255) DEFAULT NULL,
  `ItemShortDescription` varchar(255) DEFAULT NULL,
  `RetailPrice` varchar(255) DEFAULT NULL,
  `Brand` varchar(255) DEFAULT NULL,
  `Category` varchar(255) DEFAULT NULL,
  `Weight` varchar(255) DEFAULT NULL,
  `Length` varchar(255) DEFAULT NULL,
  `Width` varchar(255) DEFAULT NULL,
  `Height` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`pid`)
) ENGINE=InnoDB AUTO_INCREMENT=11387 DEFAULT CHARSET=utf8mb4;

.. but it results in an error.

enter image description here

What am I doing wrong?

0

1 Answer 1

1

As mysql documentation on load data says, the field list comes after the field/line delimiters.

LOAD DATA LOCAL INFILE 'local/path/to/file.csv' 
INTO TABLE product  
FIELDS TERMINATED BY '|' 
ESCAPED BY '"'
LINES TERMINATED BY '\n'
(ItemName,ItemShortDescription,RetailPrice,Brand,Category,@PRICE_1,@PRICE_2,@PRICE_3,Weight,Length,Width,Height)
Sign up to request clarification or add additional context in comments.

1 Comment

Darn, that was it! Thanks! :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.