【问题标题】:Unexpected behaviour in Neo4j CypherNeo4j Cypher 中的意外行为
【发布时间】:2013-11-23 22:10:25
【问题描述】:

在使用 neo4j-shell 的 Neo4j Cypher 中,我可以基于如下属性与单个节点建立关系:

match (p:Taxon{taxId:'9605'}),(t:Taxon{parentTaxId:p.taxId}) 
create unique (p)-[:PARENT_OF]->(t);

在 p 中设置 taxId 后,它按预期运行,并根据需要创建关系。但是,当我尝试通过将查询更改为将其应用于所有节点时:

match (p:Taxon),(t:Taxon{parentTaxId:p.taxId}) 
create unique (p)-[:PARENT_OF]->(t);

我收到一个错误:

NotFoundException:未知标识符t

我不明白为什么 t 现在无效。我错过了什么明显的东西吗?

【问题讨论】:

  • 啊,我明白发生了什么。第二个查询不起作用,因为有没有孩子的分类群。在这种情况下,找不到 t,因此没有要创建关系的 t。是否可以在 where 子句中添加一些东西来检测是否找不到 t?
  • 类似:匹配 (p:Taxon),(t:Taxon{parentTaxId:p.taxId}) where not(t is null) 创建唯一 (p)-[:PARENT_OF]->( t);
  • 也试过:\match (t:Taxon),(p:Taxon{taxId:t.parentTaxId}) where HAS(t.parentTaxId) create unique (p)-[:PARENT_OF]-> (t);

标签: neo4j cypher


【解决方案1】:

我认为您需要将其分解为 WHERE 子句:

MATCH (p:Taxon),(t:Taxon)
WHERE t.parentTaxId=p.taxId 
CREATE UNIQUE (p)-[:PARENT_OF]->(t);

【讨论】:

    猜你喜欢
    • 2017-02-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多