Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
02-04-2023 09:20 PM
Hello
I am using cypher below to find name of nodes from A to B, and attach the id of path to them.
MATCH p = (n1:A)-[*]->(n2:B)
WHERE not(exists((n2)-[]->(:B)))
UNWIND nodes(p) AS n3
RETURN n1.name, n3.name, reduce(x = '0', y IN nodes(p) | x + '_' + id(y)) AS pid
I get output as table below, in which rows(in yellow) containing null value in n3.name column are not expected to be output.
n1.name | n3.name | pid |
a010 | null | 0_10_1_2 |
a010 | b001 | 0_10_1_2 |
a010 | b002 | 0_10_1_2 |
a010 | null | 0_10_1_3 |
a010 | b001 | 0_10_1_3 |
a010 | b003 | 0_10_1_3 |
How can I exclude these rows from output?
Solved! Go to Solution.
02-05-2023 09:41 AM
Try this:
MATCH p = (n1:A)-[*]->(n2:B)
WHERE not(exists((n2)-[]->(:B)))
UNWIND nodes(p) AS n3
with n1, n2, n3 where n3.name is not null
RETURN n1.name, n3.name, reduce(x = '0', y IN n3 | x + '_' + id(y)) AS pid
02-05-2023 09:41 AM
Try this:
MATCH p = (n1:A)-[*]->(n2:B)
WHERE not(exists((n2)-[]->(:B)))
UNWIND nodes(p) AS n3
with n1, n2, n3 where n3.name is not null
RETURN n1.name, n3.name, reduce(x = '0', y IN n3 | x + '_' + id(y)) AS pid
02-05-2023 10:15 PM
@ameyasoft‘s solution should work. Another approach is to filter the list of nodes that gets unwinded. Replace line 4 with
unwind [n in nodes(p) where n.name is not null] as n3.
02-06-2023 06:38 PM
Thanks! This also works, too.
Thank you both!
02-06-2023 06:37 PM
Thank you! This works!
All the sessions of the conference are now available online