Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL LOAD DATA INFILE with comma as decimal separator

Tags:

mysql

How can I import a TSV file when the numbers use comma as a decimal separator?

LOAD DATA INFILE '$filename' INTO TABLE dados_meteo IGNORE 3 LINES 
($fields[0], $fields[1], $fields[2], $fields[3], $fields[4], $fields[5])
 SET POM='$pom'
 ;
like image 769
Hugo Avatar asked Jan 04 '12 23:01

Hugo


People also ask

What is Local_infile MySQL?

The local_infile system variable controls server-side LOCAL capability. Depending on the local_infile setting, the server refuses or permits local data loading by clients that request local data loading. By default, local_infile is disabled. (This is a change from previous versions of MySQL.)

How do I insert selected columns from a CSV file to a MySQL database using load data infile?

The code is like this: LOAD DATA INFILE '/path/filename. csv' INTO TABLE table_name FIELDS TERMINATED BY ',' LINES TERMINATED BY '\r\n' (column_name3, column_name5); Here you go with adding data to only two columns(you can choose them with the name of the column) to the table.

How do you load data into a MySQL table?

mysql> LOAD DATA LOCAL INFILE '/path/pet. txt' INTO TABLE pet; If you created the file on Windows with an editor that uses \r\n as a line terminator, you should use this statement instead: mysql> LOAD DATA LOCAL INFILE '/path/pet.


1 Answers

Try to replace ',' to '.' when loading.

For example -

LOAD DATA INFILE 'file.csv' INTO TABLE dados_meteo
(@var1, @var2)
SET column1 = REPLACE(@var1, ',', '.'), column2 = REPLACE(@var2, ',', '.')
like image 164
Devart Avatar answered Nov 15 '22 10:11

Devart