LOAD CSV
- 支持本地文件 import文件夹下文件
- 支持url远程文件
- 支持带头的文件
FROM本地csv
#create导入
LOAD CSV FROM "file:///a.csv" AS line CREATE (:person { name: line[1], age: toInteger(line[2])})
#更新存在的数据
LOAD CSV FROM "file:///a.csv" AS line
MATCH (n) where (n.no) = line[0] SET n.addr=line[2],n.sex=line[4]
#MERGE导入(不存在创建)
LOAD CSV FROM "file:///a.csv" AS line MERGE (p:person {no:line[0], name: line[1], age: toInteger(line[3])})
MERGE更新导入(插入和更新同时进行)
LOAD CSV FROM "file:///a.csv" AS line
MERGE (p:person {no:line[0]})
ON CREATE SET p.name=line[1],p.addr=line[2],p.sex=line[4] #插入
ON MATCH SET p.addr=line[2],p.sex=line[4] #更新
#带头导入数据
LOAD CSV WITH HEADERS FROM "file:///a.csv" AS row
MERGE (p:person {no:row.id})
ON CREATE SET p.name=row.name,p.addr=row.addr,p.sex=row.sex #插入
ON MATCH SET p.addr=row.addr,p.sex=row.sex #更新
导入关系
LOAD CSV WITH HEADERS FROM "file:///a2.csv" AS row
match (a:person {no:row.fromid}) , (b:person {no:row.toid})
MERGE (a)-[r:关系{name:row.rel}]->(b)
ON CREATE SET r.name=row.rel,r.type=row.type
ON MATCH SET r.type=row.type
删除数据
删除全部节点
match (n) delete n
删除全部节点和关系
MATCH (n)
OPTIONAL MATCH (n)-[r]-()
DELETE n, r
删除全部节点和关系
MATCH (r)
DETACH DELETE r
只删除关系
OPTIONAL MATCH (p)-[r:rela]->() return r
#查询条件删除
OPTIONAL MATCH (p)-[r:rela]->() where r.name2='他大爷' delete r