英文:
Creating a query that clones nodes and adds different properties
问题
我需要一点帮助来创建Memgraph中的特定Cyper查询。我想要复制数据库中的每个节点,并为每个节点创建3个克隆,每个克隆都有不同的属性(例如,每个克隆都有不同的id
属性)。
这是我想出的查询,但它不完全按照我想象的方式工作:
MATCH (n)
UNWIND [1, 2, 3] AS i
CREATE (copy:Clone {id: i, name: n.name + ' Clone ' + i})
SET copy.property1 ...
RETURN copy
英文:
I need a bit of help with creating a certain Cyper query in Memgraph. I want to copy each node in the database and for each create 3 clones with specifing different properties (e.g. every one of them has different id
property).
This is what I've come up with but it is not quite working as I imagined it:
MATCH (n)
UNWIND [1, 2, 3] AS i
CREATE (copy:Clone {id: i, name: n.name + ' Clone ' + i})
SET copy.property1 ...
RETURN copy
答案1
得分: 0
我认为子查询会让这个过程变得更简单。尝试运行类似这样的查询,看看结果是否符合你的要求:
MATCH (p:Person)
CALL {
FOREACH (i IN range(1, 5) | CREATE(:Person {id: i}))
}
MATCH (n) RETURN COUNT(n);
英文:
I think subqueries would make this a lot easier for you. Try running something like this query and see if the results are what you're looking for:
MATCH (p:Person)
CALL {
FOREACH (i IN range(1, 5) | CREATE(:Person {id: i}))
}
MATCH (n) RETURN COUNT(n);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论