Mysql Load File Error loading inaccurate data
up vote
0
down vote
favorite
Hi I have a csv dataset like
ukwn,34,2018-10-01,"757,271"
ukwn,3,2018-10-01,"7,342"
"hi",23,2018-10-01,"3,483,887"
i want to insert it in the database so i made the code:
LOAD DATA LOCAL INFILE 'data.csv' INTO TABLE app_spend_metric
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY 'n'
IGNORE 1 LINES
(col1,col2,col3,col4)
But i fails to insert the col4 (4th row) as there is ',' inside a "" like "7,345"
I tried then,
LOAD DATA LOCAL INFILE 'data.csv' INTO TABLE app_spend_metric
FIELDS TERMINATED BY ','
LINES TERMINATED BY 'n'
IGNORE 1 LINES
(col1,col2,col3,col4)
But this time it enters the partial data in col4 like out of "7,344" it only enters "7
mysql mariadb
add a comment |
up vote
0
down vote
favorite
Hi I have a csv dataset like
ukwn,34,2018-10-01,"757,271"
ukwn,3,2018-10-01,"7,342"
"hi",23,2018-10-01,"3,483,887"
i want to insert it in the database so i made the code:
LOAD DATA LOCAL INFILE 'data.csv' INTO TABLE app_spend_metric
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY 'n'
IGNORE 1 LINES
(col1,col2,col3,col4)
But i fails to insert the col4 (4th row) as there is ',' inside a "" like "7,345"
I tried then,
LOAD DATA LOCAL INFILE 'data.csv' INTO TABLE app_spend_metric
FIELDS TERMINATED BY ','
LINES TERMINATED BY 'n'
IGNORE 1 LINES
(col1,col2,col3,col4)
But this time it enters the partial data in col4 like out of "7,344" it only enters "7
mysql mariadb
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
Hi I have a csv dataset like
ukwn,34,2018-10-01,"757,271"
ukwn,3,2018-10-01,"7,342"
"hi",23,2018-10-01,"3,483,887"
i want to insert it in the database so i made the code:
LOAD DATA LOCAL INFILE 'data.csv' INTO TABLE app_spend_metric
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY 'n'
IGNORE 1 LINES
(col1,col2,col3,col4)
But i fails to insert the col4 (4th row) as there is ',' inside a "" like "7,345"
I tried then,
LOAD DATA LOCAL INFILE 'data.csv' INTO TABLE app_spend_metric
FIELDS TERMINATED BY ','
LINES TERMINATED BY 'n'
IGNORE 1 LINES
(col1,col2,col3,col4)
But this time it enters the partial data in col4 like out of "7,344" it only enters "7
mysql mariadb
Hi I have a csv dataset like
ukwn,34,2018-10-01,"757,271"
ukwn,3,2018-10-01,"7,342"
"hi",23,2018-10-01,"3,483,887"
i want to insert it in the database so i made the code:
LOAD DATA LOCAL INFILE 'data.csv' INTO TABLE app_spend_metric
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY 'n'
IGNORE 1 LINES
(col1,col2,col3,col4)
But i fails to insert the col4 (4th row) as there is ',' inside a "" like "7,345"
I tried then,
LOAD DATA LOCAL INFILE 'data.csv' INTO TABLE app_spend_metric
FIELDS TERMINATED BY ','
LINES TERMINATED BY 'n'
IGNORE 1 LINES
(col1,col2,col3,col4)
But this time it enters the partial data in col4 like out of "7,344" it only enters "7
mysql mariadb
mysql mariadb
asked Nov 8 at 14:17
user9092050
54
54
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
If col4 is numeric (eg, INT
), then the problem is as follows:
- Parse the line to get the string
"7,344"
- Strip the enclosing
"
:7,344
- Store the string into the
INT
column. This requires converting that string to a number. - Conversion stops at the first non-numeric character, namely the comma.
- Result: The
col4
is set to 7, and,344
is tossed.
MySQL cannot deal with "thousands-separators" in numbers. But you could strip them:
LOAD ...
(col1, col2, col3, @num)
SET col4 = REPLACE(@num, ',', '')
Hi, there are 4 colums
– user9092050
17 hours ago
@user9092050 - I rewrote my answer to explain how to parse the commas.
– Rick James
11 hours ago
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
If col4 is numeric (eg, INT
), then the problem is as follows:
- Parse the line to get the string
"7,344"
- Strip the enclosing
"
:7,344
- Store the string into the
INT
column. This requires converting that string to a number. - Conversion stops at the first non-numeric character, namely the comma.
- Result: The
col4
is set to 7, and,344
is tossed.
MySQL cannot deal with "thousands-separators" in numbers. But you could strip them:
LOAD ...
(col1, col2, col3, @num)
SET col4 = REPLACE(@num, ',', '')
Hi, there are 4 colums
– user9092050
17 hours ago
@user9092050 - I rewrote my answer to explain how to parse the commas.
– Rick James
11 hours ago
add a comment |
up vote
0
down vote
If col4 is numeric (eg, INT
), then the problem is as follows:
- Parse the line to get the string
"7,344"
- Strip the enclosing
"
:7,344
- Store the string into the
INT
column. This requires converting that string to a number. - Conversion stops at the first non-numeric character, namely the comma.
- Result: The
col4
is set to 7, and,344
is tossed.
MySQL cannot deal with "thousands-separators" in numbers. But you could strip them:
LOAD ...
(col1, col2, col3, @num)
SET col4 = REPLACE(@num, ',', '')
Hi, there are 4 colums
– user9092050
17 hours ago
@user9092050 - I rewrote my answer to explain how to parse the commas.
– Rick James
11 hours ago
add a comment |
up vote
0
down vote
up vote
0
down vote
If col4 is numeric (eg, INT
), then the problem is as follows:
- Parse the line to get the string
"7,344"
- Strip the enclosing
"
:7,344
- Store the string into the
INT
column. This requires converting that string to a number. - Conversion stops at the first non-numeric character, namely the comma.
- Result: The
col4
is set to 7, and,344
is tossed.
MySQL cannot deal with "thousands-separators" in numbers. But you could strip them:
LOAD ...
(col1, col2, col3, @num)
SET col4 = REPLACE(@num, ',', '')
If col4 is numeric (eg, INT
), then the problem is as follows:
- Parse the line to get the string
"7,344"
- Strip the enclosing
"
:7,344
- Store the string into the
INT
column. This requires converting that string to a number. - Conversion stops at the first non-numeric character, namely the comma.
- Result: The
col4
is set to 7, and,344
is tossed.
MySQL cannot deal with "thousands-separators" in numbers. But you could strip them:
LOAD ...
(col1, col2, col3, @num)
SET col4 = REPLACE(@num, ',', '')
edited 11 hours ago
answered Nov 8 at 20:00
Rick James
63.8k55593
63.8k55593
Hi, there are 4 colums
– user9092050
17 hours ago
@user9092050 - I rewrote my answer to explain how to parse the commas.
– Rick James
11 hours ago
add a comment |
Hi, there are 4 colums
– user9092050
17 hours ago
@user9092050 - I rewrote my answer to explain how to parse the commas.
– Rick James
11 hours ago
Hi, there are 4 colums
– user9092050
17 hours ago
Hi, there are 4 colums
– user9092050
17 hours ago
@user9092050 - I rewrote my answer to explain how to parse the commas.
– Rick James
11 hours ago
@user9092050 - I rewrote my answer to explain how to parse the commas.
– Rick James
11 hours ago
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53209603%2fmysql-load-file-error-loading-inaccurate-data%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password