执行 DELETE 后什么都没有
Nothing after DELETE gets executed
我有以下查询:
MATCH (u:User)
WHERE u.id = $userId
MERGE (p:Palette {name: $name})
ON CREATE
SET p.name = $name
SET p.id = apoc.create.uuid()
MERGE (u)-[cr:CREATED]->(p)
MERGE (u)-[sa:SAVED]->(p)
WITH p MATCH (p)-[in:INCLUDES]->()
DELETE in
WITH u MATCH (p:Palette)
WHERE (u)-[:SAVED]-() AND p.name = $name
FOREACH (color IN $colors |
MERGE (c:Color {hex: color.hex})
ON CREATE
SET c.hex = color.hex
MERGE (p)-[inc:INCLUDES]->(c)
在 DELETE in
之前一切都按预期工作,然后没有其他任何事情发生。我收到以下错误:
Neo4jError: Invalid input '': expected
")"
"CALL"
"CREATE"
"DELETE"
"DETACH"
"FOREACH"
"LOAD"
"MATCH"
"MERGE"
"ON"
"OPTIONAL"
"REMOVE"
"RETURN"
"SET"
"UNWIND"
"USE"
"WITH"
如何在 DELETE statement
之后继续此查询?如果我将其分成 2 个查询(第一个以 DELETE in
结尾),那么一切都会按预期进行。
如果我没理解错的话,DELETE
前面的p
和后面的p
是一样的。如果是这种情况,请使用 WITH
保留您已经搜索过的项目。所以你可以试试:
MATCH (u:User)
WHERE u.id = $userId
MERGE (p:Palette {name: $name})
ON CREATE
SET p.name = $name
SET p.id = apoc.create.uuid()
MERGE (u)-[cr:CREATED]->(p)
MERGE (u)-[sa:SAVED]->(p)
WITH p, u MATCH (p)-[inc:INCLUDES]->()
WITH p, u, inc
DELETE inc
WITH p
FOREACH (color IN $colors |
MERGE (c:Color {hex: color.hex})
ON CREATE
SET c.hex = color.hex
MERGE (p)-[inc:INCLUDES]->(c)
我试过了:
MATCH (p:Palette)
WHERE p.name = "First test palette"
MATCH (p)-[inc:INCLUDES]->(c:Color)
WITH p, inc
DELETE inc
WITH p
MATCH (u)-[:SAVED]-(p)
RETURN u, p
关于这个数据样本:
MERGE (e:User {name: "user"})
MERGE (a:Palette {name: "First test palette"})
MERGE (b:Color {hex: "#123123"})
MERGE (c:Color {hex: "#ffffff"})
MERGE (d:Color {hex: "#000000"})
MERGE (a)-[:INCLUDES]-(b)
MERGE (a)-[:INCLUDES]-(c)
MERGE (a)-[:INCLUDES]-(d)
MERGE (e)-[:SAVED]-(a)
它按预期工作。
我有以下查询:
MATCH (u:User)
WHERE u.id = $userId
MERGE (p:Palette {name: $name})
ON CREATE
SET p.name = $name
SET p.id = apoc.create.uuid()
MERGE (u)-[cr:CREATED]->(p)
MERGE (u)-[sa:SAVED]->(p)
WITH p MATCH (p)-[in:INCLUDES]->()
DELETE in
WITH u MATCH (p:Palette)
WHERE (u)-[:SAVED]-() AND p.name = $name
FOREACH (color IN $colors |
MERGE (c:Color {hex: color.hex})
ON CREATE
SET c.hex = color.hex
MERGE (p)-[inc:INCLUDES]->(c)
在 DELETE in
之前一切都按预期工作,然后没有其他任何事情发生。我收到以下错误:
Neo4jError: Invalid input '': expected ")" "CALL" "CREATE" "DELETE" "DETACH" "FOREACH" "LOAD" "MATCH" "MERGE" "ON" "OPTIONAL" "REMOVE" "RETURN" "SET" "UNWIND" "USE" "WITH"
如何在 DELETE statement
之后继续此查询?如果我将其分成 2 个查询(第一个以 DELETE in
结尾),那么一切都会按预期进行。
如果我没理解错的话,DELETE
前面的p
和后面的p
是一样的。如果是这种情况,请使用 WITH
保留您已经搜索过的项目。所以你可以试试:
MATCH (u:User)
WHERE u.id = $userId
MERGE (p:Palette {name: $name})
ON CREATE
SET p.name = $name
SET p.id = apoc.create.uuid()
MERGE (u)-[cr:CREATED]->(p)
MERGE (u)-[sa:SAVED]->(p)
WITH p, u MATCH (p)-[inc:INCLUDES]->()
WITH p, u, inc
DELETE inc
WITH p
FOREACH (color IN $colors |
MERGE (c:Color {hex: color.hex})
ON CREATE
SET c.hex = color.hex
MERGE (p)-[inc:INCLUDES]->(c)
我试过了:
MATCH (p:Palette)
WHERE p.name = "First test palette"
MATCH (p)-[inc:INCLUDES]->(c:Color)
WITH p, inc
DELETE inc
WITH p
MATCH (u)-[:SAVED]-(p)
RETURN u, p
关于这个数据样本:
MERGE (e:User {name: "user"})
MERGE (a:Palette {name: "First test palette"})
MERGE (b:Color {hex: "#123123"})
MERGE (c:Color {hex: "#ffffff"})
MERGE (d:Color {hex: "#000000"})
MERGE (a)-[:INCLUDES]-(b)
MERGE (a)-[:INCLUDES]-(c)
MERGE (a)-[:INCLUDES]-(d)
MERGE (e)-[:SAVED]-(a)
它按预期工作。