创建一个克隆节点并添加不同属性的查询

huangapple go评论52阅读模式
英文:

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);

huangapple
  • 本文由 发表于 2023年4月13日 16:33:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/76003329.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定