如何将\ data \ ^ Ihello $加载为两列?

时间:2018-08-27 05:28:24

标签: mysql escaping load

这是我的test-tab.csv,如下所示。

\data\  hello

注意:\t\h之间有一个test-tab.csv,也就是说,显示在vim(集合列表)中。

\data\^Ihello$

准备加载数据。

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

将数据加载到表tab中。

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

看看。

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

如何将数据加载到表tab中,如下所示。

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

约束条件:保持test-tab.csv中的数据格式不变。

2 个答案:

答案 0 :(得分:5)

问题似乎是在转义标签。

FIELDS TERMINATED BY '\t' ESCAPED BY ''

如果这不起作用,是否有一些未在数据中使用的字符?说|?然后

FIELDS TERMINATED BY '\t' ESCAPED BY '|'

答案 1 :(得分:0)

type Device {
  id: ID!
  name: String
  # Get the most recent readings for this device.
  # Do a Query where "device = $ctx.source.id"
  readings(limit: Int, nextToken: String): ReadingConnection 
}

type Reading {
  # Use the source's device id in the table to fetch the real device
  # GetItem where device = $ctx.source.device (and any sort key condition)
  device: Device 
  time: Int
  cow: Int
  battery: String
}

type ReadingConnection {
  items: [Reading]
  nextToken: String
}

type DeviceConnection {
  items: [Device]
  nextToken: String
}

type Query {
  getAllDevices(limit: Int, nextToken: String): DeviceConnection
}

1.add query GetAllDevicesAndReadings { getAllDevices(first: 10) { items { id name readings(limit: 10) { time cow battery } } } }
2。LOAD DATA LOCAL INFILE "f:/test-tab.csv" INTO TABLE tab FIELDS TERMINATED BY '\t' ESCAPED BY '' LINES TERMINATED BY '\n' \W;
csv文件是在linux中创建的,我将其加载到win-os中。