1

I am using LOAD DATA local INFILE command to upload big csv file in mysql db. The field is an integer in the mysql table and so it will accept only integer.

Now if the csv file contains numbers like below then the sql doesn't work.The format of my csv file is

ID
"322"
"445"
"211"

So it is inserting 0 in the table. But if the csv file contains no double quotes then it's fine.

How can I tell "load data infile" command to ignore double quotes( as sometimes it is too difficult to remove double quotes from csv file which has got about 1 million records).My Sql is

$insert_query = "LOAD DATA local INFILE '".$target_path."'
                INTO table master_huts
                IGNORE 1 LINES
                (hids)
                ";
1

1 Answer 1

1

Try adding this:

FIELDS OPTIONALLY ENCLOSED BY '"'

before:

IGNORE 1 LINES
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks.Now getting php parsing error.If you see my sql it starts with "
Solved the parsing issue by using '\"' but now getting sql error now.
I am sooo stupid...How can I do such idiotic mistake.I am so sorry @spencer7593 and thank you so much for your help.Accepted the answer.
My answer was focused on the SQL statement; getting that string specified as a string literal within PHP (or Java or whatever language), that introduces the need to "escape" characters within the string. You figured out you needed the backslash before the double quote...

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.