英文:
When executing the CREATE query I get the error about Bidirectional relationship
问题
执行查询CREATE (h:Human)-[l:LOVES]-(f:Foof) RETURN h, l, f;
时,我收到以下错误:
错误: 查询失败: 在创建边时不支持双向关系
如果我使用MERGE而不是CREATE,则关系会被创建:
MERGE (h:Human)-[l:LOVES]-(f:Foof) RETURN h, l, f
为什么会这样?
英文:
When I execute the query CREATE (h:Human)-[l:LOVES]-(f:Foof) RETURN h, l, f;
, I get the following error:
Error: Query failed: Bidirectional relationship are not supported when creating an edge
If I use MERGE instead of CREATE, the relationship is created:
MERGE (h:Human)-[l:LOVES]-(f:Foof) RETURN h, l, f
Why is this so?
答案1
得分: 0
假设Memgraph遵循openCypher规范,对于没有指定方向的MERGE,规范允许实现选择一个方向。虽然这意味着查询可以工作,但提供一个明确的边方向会更好(也更安全)。
具体的指导信息在上面链接的文档的第119页上给出,其中指出:
MERGE也可以与无方向的关系一起使用。当需要创建一个新的关系时,它将选择一个方向。
英文:
Assuming that Memgraph is following the openCypher specification, for a MERGE where no direction is specified, the spec allows the implementation to pick a direction. While this means the query will work, it's going to be better (and safer) to provide an explicit edge direction.
The specific guidance is given on Page 119 of the document linked above, where it states:
>MERGE can also be used with an undirected relationship. When it needs to create a new one, it will
pick a direction.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论