Neo4j仅在唯一时加载CSV [英] Neo4j Load CSV only when unique
本文介绍了Neo4j仅在唯一时加载CSV的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我的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
是唯一时加载,因此在上述情况下,我只会创建Trip 3次.我该怎么办?
and I want to load only when trip_headsign
is unique, so in above case I would only create Trip 3 times. How do i do it?
我到目前为止如下:
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'
我有意将首字母签名作为唯一约束,因为我只希望每个签名仅存在一次.
I have intentionally keps headsign as unique constraint because I only want everyone of it to exist only once.
推荐答案
我现在想通了.谢谢
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
这篇关于Neo4j仅在唯一时加载CSV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文