我有以下密码代码
CALL apoc.periodic.iterate(
"LOAD CSV WITH HEADERS FROM $url AS row
WITH row {{.*}}
RETURN row",
"CALL apoc.merge.node(['House'],
{{id : row.ID}},
apoc.map.submap(row,['household']),
apoc.map.submap(row,['household']))
YIELD node AS n1
CALL apoc.create.addLabels(n1, ['House'])
YIELD node as n2
CREATE CONSTRAINT constraint_name IF NOT EXISTS ON (n:House) ASSERT n.household IS UNIQUE
YIELD node as n3
RETURN COUNT(n1)
",
{{batchSize: {batch_size}, iterateList: true, parallel:false, params: {{url: '{url}'}} }})
我得到errorMessages':{'无效输入'a':期望'u/u '创建约束constraint_name如果不存在ON (n:House)断言n.household是唯一的}你知道如何解决这个问题吗?
您使用的CREATE CONSTRAINT
是无效的-它不应该是Cypher查询的一部分,例如LOAD CSV。
先创建约束:
CREATE CONSTRAINT constraint_name IF NOT EXISTS ON (n:House) ASSERT n.household IS UNIQUE
然后你可以运行一个新的Cypher语句来加载数据
无关的注意:您不需要使用apoc.periodic.iterate来批处理LOAD CSV,您也可以使用定期提交https://neo4j.com/docs/cypher-manual/current/clauses/load-csv/#load-csv-setting-the-rate-of-periodic-commits