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

Viewed 117

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.

2 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 '|'
LOAD DATA LOCAL INFILE  "f:/test-tab.csv"
INTO TABLE  tab
FIELDS TERMINATED BY '\t'   ESCAPED BY ''
LINES TERMINATED BY '\n'  \W;

1.add ESCAPED BY ''
2.LINES TERMINATED BY '\n'
The csv file was created in linux,i load it in my win-os.

Related