[英]Use variable to match a node label in Neo4J CYPHER
I will be running some complex MATCH which will return a node label to me. 我将运行一些复杂的MATCH,它将向我返回一个节点标签。 Then I want to trim the prefix of that node label and use the rest of it to further perform matches.
然后,我想修剪该节点标签的前缀,并使用其其余部分进一步执行匹配。 I am trying to do this by assigning that rest of the part of the returned label to the variable and then using that variable to the label the node in
MATCH
. 我正在尝试通过将返回标签的其余部分分配给变量,然后将该变量用于标签来
MATCH
的节点来做到这一点。
However I feel this does not work since we cannot use a variable to label a node in MATCH
. 但是我觉得这行不通,因为我们不能在
MATCH
使用变量来标记节点。
For example create simple two node graph: 例如,创建简单的两个节点图:
CREATE (:PrefixNodeLabel)
CREATE (:NodeLabel)
This: 这个:
MATCH(n:PrefixNodeLabel)
RETURN substring(labels(n)[0],6)
correctly returns NodeLabel
. 正确返回
NodeLabel
。
I am trying to use this to label a node: 我试图用它来标记一个节点:
MATCH(n:PrefixNodeLabel)
WITH substring(labels(n)[0],6) AS nodeLabel
MATCH(m:nodeLabel) //using a variable to label a node
RETURN m
But this does not return the (:NodeLabel)
node. 但这不会返回
(:NodeLabel)
节点。
I know what I am doing may look weird. 我知道我在做什么可能看起来很奇怪。 But anyway how do I do this?
但是无论如何我该怎么做?
you cannot pass variable in place of Label 您不能通过变量代替Label
You can achieve this by 您可以通过实现
MATCH (n:PrefixNodeLabel)
WITH SUBSTRING(labels(n)[0],2) AS nodeLabel
MATCH (m)
WHERE nodeLabel IN LABELS(m)
RETURN m
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.