Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
01-14-2020 03:38 PM
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 |
?
Solved! Go to Solution.
01-14-2020 03:48 PM
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).
01-14-2020 03:48 PM
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).
01-14-2020 04:13 PM
Understood! Thank You again!
01-14-2023 01:29 PM
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() .
All the sessions of the conference are now available online