MySQL bulk load

我是研究僧i 提交于 2019-12-24 21:11:42

问题


I'm trying to load csv files into mysql table. Delimiter : ,(comma)

As part of the source data few of the field values are enclosed in double quotes and inside the double quotes we have , There are few records for which / is part of the field data and we need to escape it.

By default / is getting escaped and when I specified the " as escape character " is getting escaped. As we have multiple special characters inside the same file, we need to escape multiple special characters.

Any suggestion

Eg:

 id name location
 1  A   "Location , name here"
 2  B   "Different Location"
 3  C   Another Location
 4  D   Location / with escape character  

LOAD DATA LOCAL INFILE 'data.csv' INTO TABLE table_name FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n' IGNORE 1 LINES;

回答1:


I think it's not possible. Referring to LOAD DATA reference

Any of the field- or line-handling options can specify an empty string (''). If not empty, the FIELDS [OPTIONALLY] ENCLOSED BY and FIELDS ESCAPED BY values must be a single character.

Only a single char is supported for ESCAPED BY field. My proposal is to use any programming language (e.g. PHP, C# etc.) for opening and processing file line-by-line using regexp



来源:https://stackoverflow.com/questions/52383171/mysql-bulk-load

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!