Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to load `\data\^Ihello$` as two columns?

It is my test-tab.csv as below.

\data\  hello

Notice:there is a \t between \ and h in test-tab.csv,that is to say ,showing in vim(set list).

\data\^Ihello$

Prepare for loading data.

create table tab(`f1` varchar(10),`f2` varchar(10));

Load the data into table tab.

LOAD DATA LOCAL INFILE  "f:/test-tab.csv"
INTO TABLE  tab
FIELDS TERMINATED BY '\t'
LINES TERMINATED BY '\r\n'  \W;

And have a look.

select * from tab;
+------------+------+
| f1         | f2   |
+------------+------+
| data  hello| NULL |
+------------+------+
1 row in set (0.000 sec)

How can i load data into table tab as below.

select * from tab;
+------------+------+
| f1         | f2   |
+------------+------+
| \data\     | hello|
+------------+------+
1 row in set (0.000 sec)

Constraint condition:keep the data format in test-tab.csv unchanged.

like image 790
showkey Avatar asked Aug 27 '18 05:08

showkey


1 Answers

The problem seems to be escaping the tab.

FIELDS TERMINATED BY '\t' ESCAPED BY ''

If that does not work, is there some character that is not used in the data? Say |? Then

FIELDS TERMINATED BY '\t' ESCAPED BY '|'
like image 121
Rick James Avatar answered Nov 17 '22 14:11

Rick James