无法访问`WITH`/`UNWIND`子句中的变量,正在Neo4j中插入ID数组

yk9xbfzb  于 2022-10-01  发布在  其他
关注(0)|答案(1)|浏览(134)

似乎我在WITHUNWIND子句中定义的任何变量在子句中都不可用。

我想知道为什么这个查询返回未定义owner

MATCH (owner:User { id: 'b6bba33e-646a-46c2-80a2-4b6a6b5cece9' })
// Create one coaching that has two participants (WITH clause)
CREATE (coaching:Coaching {
  id: randomUUID(),
  subject: 'Testing coaching 1' ,
  notes: 'testing this new feature',
  createdAt: DateTime()
})<-[:COACHES]-(owner)

WITH ['e1d8aaef-8db6-4dc1-8f3e-1bce06463d04', '6c20b918-284c-42a9-bc6f-ab4f99a09f2f'] AS participants
UNWIND participants AS p
MATCH (participant:User { id: p })
// Create relationship participant PARTICIPATES in coaching
CREATE (coaching)<-[:PARTICIPATES]-(participant)

RETURN owner, coaching, p
Variable `owner` not defined (line 16, column 8 (offset: 536))
"RETURN owner, coaching, p"
bqucvtff

bqucvtff1#

我需要将变量添加到WITH子句中。

...
WITH ['e1d8aaef-8db6-4dc1-8f3e-1bce06463d04', '6c20b918-284c-42a9-bc6f-ab4f99a09f2f'] AS participants, owner, coaching
UNWIND participants AS p
MATCH (participant:User { id: p })
// Create relationship participant PARTICIPATES in coaching
CREATE (coaching)<-[:PARTICIPATES]-(participant)
...

相关问题