我正在尝试将数据加载到我已创建的表中。这就是目前的情况:
CREATE TABLE Users (
id int CHECK(id>0),
pic varchar(100),
url varchar(100),
name varchar(200),
type varchar(10),
PRIMARY KEY(id)
) ENGINE=InnoDB;
数据的格式如下:
{"id":195624,"pic":"d1qb2nb5cznatu.cloudfront.net/users/195624-medium_jpg?1405525524","url":"angel.co/startup-ucla-accelerator","name":"Startup UCLA Accelerator","type":"User"},{"id":621586,"pic":null,"url":"angel.co/terri-getzug","name":"Terri Getzug, MD Clinical Professor of Medicine, Division of Digestive Diseases, David Geffen School of Medicine at UCLAepartment of Medicine","type":"User"}
所有元组都在一行中,每个元组都包含在{}中。
如何在删除额外属性名称的同时将数据加载到我的表中?
我尝试过类似的东西:
LOAD DATA LOCAL INFILE './users.del' INTO TABLE Users FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES STARTING BY '{' TERMINATED BY '},' (id, pic, url, name, type)
SET id = TRIM(LEADING '"id":'),
pic = TRIM(LEADING ',"pic":'),
url = TRIM(LEADING ',"url":'),
name = TRIM(LEADING ',"name":'),
type = TRIM(LEADING ',"type":');