如果我有csv如下:
"route_id","service_id","trip_id","trip_headsign"
4973_3, 2, 14519396, "Bf. Tostedt"
4973_3, 2, 14519395, "Bf. Tostedt"
4973_3, 1, 14519379, "Sittensen, Schule"
4973_3, 1, 14519391, "Sittensen, Bahnhofstraße"
4973_3, 2, 14519394, "Bf. Tostedt"
4973_3, 1, 14519390, "Bf. Tostedt"
4973_3, 3, 14519381, "Bf. Tostedt"
4973_3, 4, 14519392, "Bf. Tostedt"
我只想在trip_headsign
唯一时加载,所以在上面的情况下我只会创建3次旅行。我该怎么做?
我到目前为止:
load csv with headers from
'file:///hamburg/trips.txt' as csv
create (t:Trip {id: csv.trip_id, service_id: csv.service_id, headsign: csv.trip_headsign});
但是我收到了这个错误:
Node(76020) already exists with label `Trip` and property `headsign` = 'Bf. Tostedt'
我故意将keign标记为唯一约束,因为我只希望它的每个人只存在一次。
答案 0 :(得分:3)
我现在想通了。感谢
load csv with headers from
'file:///hamburg/trips.txt' as csv
merge (t:Trip {headsign: csv.trip_headsign})
on match set t.id = csv.trip_id
on match set t.service_id = csv.service_id