Head's Up! Site migration is underway. Phase 2: migrate recent content
β01-11-2022 02:12 AM
I would like to delete some relationships in a graph first, and then find all pair shortest path.
Step1: MATCH (n {happy: false})-[r]-() DELETE r
Step2: MATCH p=allShortestPaths((h)-[*1..20]->(k {value:true}))
How can I combine these two steps in one query?
β01-11-2022 05:43 PM
I don't think you can. It looks like DELETE is a terminal operation. I tried the query below to test. Although it executed without an error and deleted the relationship, it did not return the nodes n and m, even though a result is obtained if the second match/return is executed by itself. I suspect nothing is returned from the delete, so the query stops after the delete.
match(n{key:3})-[r:CONNECTED_TO]->(m{key:4}) delete r
with n
match(n{key:1})-[:CONNECTED_TO]->(m{key:2})
return n, m
β01-12-2022 12:22 AM
Hello @lingxuan9
There is a workaround using the UNION
keyword but this is an abuse and there is no guarantee that it will work in the future:
MATCH (n {happy: false})-[r]-() DELETE r
UNION
MATCH p=allShortestPaths((h)-[*1..20]->(k {value:true}))
The best option is to stick to two queries.
Regards,
Cobra
β01-12-2022 01:29 AM
Thanks Cobra, I try it. But it shows
"All sub queries in an UNION must have the same column names"
β01-12-2022 01:34 AM
So it was patched It was working on previous versions.
Can you try:
MATCH (n {happy: false})-[r]-() DELETE r
WITH *
MATCH p = allShortestPaths((h)-[*1..20]->(k {value:true}))
RETURN p
All the sessions of the conference are now available online