cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

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

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

3 REPLIES 3

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!

Thanks for your clarification.

If I may, I want to add one remark. Since this usage of pipe has nothing to do with the common semantic of this symbol, it would be nice if the syntax would be described in other parts of the documentation in the similar way like it has been done in the section dedicated to reduce() .