0

I have .csv file data like this:

"UPRR 38 PAN AM "M"","1"

and I loaded data into table using below command which is having two columns (a and b).

LOAD DATA LOCAL INFILE 'E:\monthly_data.csv'
INTO TABLE test_data_table
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\r\n';

But when I select table, it's giving unexpected results which is shown below.

a contains:

UPRR 38 PAN AM "M","1

... and b is NULL.

Thanks

1

2 Answers 2

2

You can replace all the instances of "Double quote double quote" in your file

either A. open the files and find replace them or B. make a script to open the files and replace the extra quote that is messing it up

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

Comments

1

You have this:

ENCLOSED BY '"'

Thus " is not a regular character any more. It's a special character that has a special meaning: it highlights the start and end of a column value. If you want to type a " that does not behave that way you need to escape it. The RFC 4180 - Common Format and MIME Type for Comma-Separated Values (CSV) Files document explains how to do that:

If double-quotes are used to enclose fields, then a double-quote appearing inside a field must be escaped by preceding it with another double quote

a;b
"UPRR 38 PAN AM ""M""";1

As they say, garbage in, garbage out ;-)

2 Comments

Thanks for your answer @Alvaro but i have 1 million records with same case, how can i add another double quote to escape it.
Why do you have 1 million records of broken data in the first place?

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.