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

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 |?

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).

2 Likes

Understood! Thank You again!