gpt4 book ai didi

java - Neo4j:在 JDBC 中不支持创建唯一的

转载 作者:行者123 更新时间:2023-12-01 20:24:15 24 4
gpt4 key购买 nike

我必须在 Neo4j 中创建唯一的节点,但是这个查询不正确,因为 Neo4j 说

This pattern is not supported for CREATE UNIQUE

List<String> users = pUsers.collect();
for(String u : users){
if(u.equals("error"))
continue;
else{
String cql = " CREATE UNIQUE (n:User {value:'" + u +"'})";
st.executeUpdate(cql);
}

如何解决?

最佳答案

使用之前CREATE UNIQUE您需要MATCH一个节点。之后,使用匹配的节点在图中创建唯一的模式。 CREATE UNIQUE 将在图表中进行最小的更改。我相信您需要的是MERGE。 CREATE UNIQUE 文档说:

MERGE might be what you want to use instead of CREATE UNIQUE. Note however, that MERGE doesn’t give as strong guarantees for relationships being unique.

因此您可以调整代码以:

List<String> users = pUsers.collect();
for(String u : users){
if(u.equals("error"))
continue;
else{
String cql = "MERGE (n:User {value:'" + u +"'})";
st.executeUpdate(cql);
}
}

查看this answer .

关于java - Neo4j:在 JDBC 中不支持创建唯一的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44136967/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com