cancel
Showing results for 
Search instead for 
Did you mean: 

Join the community at Nodes 2022, our free virtual event on November 16 - 17.

Documentation for using pipe (|) operator for list operations in Cypher

manish_giri_me
Node Clone

Hello,

I've been trying to find some documentation for the pipe operator (|) when used with list operations in Cypher, but I couldn't find anything. This documentation on the FOREACH clause also uses | in the query, but again, there's no reference to what it does -

MATCH p =(begin)-[*]->(END )
WHERE begin.name = 'A' AND END .name = 'D'
FOREACH (n IN nodes(p)| SET n.marked = TRUE )

I know what the query does here, but what is the purpose of the |?

A similar query I created while playing with the Movies graph -

MATCH path=(p:Person)-[:ACTED_IN]->(m:Movie)
RETURN [n in nodes(path) | labels(n)[0]]

This returns -

My rough guess is that the | behaves like "for this, do that", but this is just my guess. Is there some other documentation that explains |?

1 ACCEPTED SOLUTION

It's not an operator on its own, it is basically a divider that usually means, as you put it, "for this, do that." These should be the most frequent usages:

You can see this in FOREACH, where it divides the list iteration part from the Cypher to be executed for each list element.

It's also in the reduce() function, where it separates the accumulating variable and list iteration part from the updating expression.

When used in list comprehensions or pattern comprehensions it divides the list iteration part (or the pattern for the pattern comprehension) from the projection expression (what to project from the list element or from a matched pattern as a new list element).

View solution in original post

2 REPLIES 2

It's not an operator on its own, it is basically a divider that usually means, as you put it, "for this, do that." These should be the most frequent usages:

You can see this in FOREACH, where it divides the list iteration part from the Cypher to be executed for each list element.

It's also in the reduce() function, where it separates the accumulating variable and list iteration part from the updating expression.

When used in list comprehensions or pattern comprehensions it divides the list iteration part (or the pattern for the pattern comprehension) from the projection expression (what to project from the list element or from a matched pattern as a new list element).

Understood! Thank You again!