3

I made a importer for the csv files for the customer and the problem which I have is that I get truncated values for decimal values in the file, example:

in .csv file price is 12,23
and in database it is saved as 12.

I checked the fields, they are set to decimal(10,2) so this shouldnt be usual. My code for loading file is:

LOAD DATA LOCAL INFILE "U:/v7/root/file/docimport/3/87/article.csv" 
INTO TABLE im_artikel 
CHARACTER SET latin1 FIELDS TERMINATED BY ";" IGNORE 1 LINES 
(article,price,grossprice);
show WARNINGS;

And I get an error:

1265 Data truncated for column 'price' at row 1
1265 Data truncated for column 'grossprice' at row 1

.Csv file looks like this:

Shoes;40,00;21,46

I could change all the fields to varchar than I dont have problems, but I think this is not the solution.

9
  • 1
    possible duplicate of Change decimal separator in MySQL Commented Feb 11, 2014 at 8:59
  • 2
    MySQL uses . as the decimal separator, not ,. Commented Feb 11, 2014 at 9:00
  • I dont feel good with changing data for 60k records :/ Commented Feb 11, 2014 at 9:00
  • Well, that's just too bad. Commented Feb 11, 2014 at 9:01
  • just open it up in a text editor and run replace-all? :) Commented Feb 11, 2014 at 9:02

1 Answer 1

7

Please have a try with this:

LOAD DATA LOCAL INFILE "U:/v7/root/file/docimport/3/87/article.csv" 
INTO TABLE im_artikel 
CHARACTER SET latin1 FIELDS TERMINATED BY ";" IGNORE 1 LINES 
(article,@p,@gp)
SET price = REPLACE(@p, ',', '.'), grossprice = REPLACE(@gp, ',', '.');
Sign up to request clarification or add additional context in comments.

Comments

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.