MySQL Forums
Forum List  »  Newbie

Loading CSV Data with commas
Posted by: Jim Palmer
Date: May 19, 2021 05:36AM

Trying to load table from csv where column values contain commas. Not getting result that I expect.
Here is a summary of my efforts:

Table Definition:

CREATE TABLE finances.MCC_Codes
(
row_id integer auto_increment,
mcc_code varchar(5),
end_mcc_code varchar(5),
mcc_description varchar(255),
primary key(row_id)
);

MCC_Short.csv File Contains:

00000,,Payment
00742,,Veterinary Services
00763,,Agricultural Cooperative
00780,,Landscaping Services
01520,,General Contractors
01711,,"Heating, Plumbing, A/C"
01731,,Electrical Contractors
01740,,"Masonry, Stonework, and Plaster"


LOAD SQL Statements:

LOAD DATA LOCAL INFILE 'Users/jkpalmer/Desktop/MCC_Short.csv'
INTO TABLE finances.MCC_Codes
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'
(mcc_code, end_mcc_code, mcc_description)
set
row_id = null;

SELECT * FROM finances.MCC_Codes;

LOAD Result:

07:04:51
LOAD DATA LOCAL INFILE 'Users/jkpalmer/Desktop/MCC_Short.csv'
INTO TABLE finances.MCC_Codes
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'
(mcc_code, end_mcc_code, mcc_description)
set row_id = null
6 row(s) affected, 1 warning(s): 1265 Data truncated for column 'mcc_description' at row 6 Records: 6 Deleted: 0 Skipped: 0 Warnings: 1 0.028 sec

Rows 7 and 8 do not get loaded and row 6 doesn't appear to be populated correctly.

MCC_Codes - Table Contents - Exported using MySQL Workbench:
row_id,mcc_code,end_mcc_code,mcc_description
1,00000,,"Payment
"
2,00742,,"Veterinary Services
"
3,00763,,"Agricultural Cooperative
"
4,00780,,"Landscaping Services
"
5,01520,,"General Contractors
"
6,01711,,"Heating, Plumbing, A/C"
01731,,Electrical Contractors
01740,,"Masonry, Stonework, and Plaster"

Help greatly appreciated.

Regards,

Jim P.

Options: ReplyQuote




Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.