diff --git a/docs/clauses/return.md b/docs/clauses/return.md index 4499ffda7..779d9186b 100644 --- a/docs/clauses/return.md +++ b/docs/clauses/return.md @@ -333,6 +333,75 @@ Result +## Pattern expressions in projections + +A *pattern expression* is a path pattern, such as `(a)-[:KNOWS]->(:Person)`, used in a position where a value is expected. It evaluates to a boolean that is `true` when at least one matching path exists. In addition to being used as a predicate in a `WHERE` clause, a pattern expression can be returned directly from a `RETURN` (or `WITH`) projection. + +Query + + +```postgresql +SELECT * +FROM cypher('graph_name', $$ + MATCH (a:Person) + RETURN a.name, (a)-[:KNOWS]->(:Person) AS knows_someone + ORDER BY a.name +$$) as (name agtype, knows_someone agtype); +``` + + +For each person, this returns a boolean indicating whether they have an outgoing `KNOWS` relationship to another `Person`. + +Result + + +
| name + | +knows_someone + | +
| "A" + | +true + | +
| "B" + | +true + | +
| "C" + | +true + | +
| "D" + | +false + | +
| "D" + | +false + | +
| (5 rows) + | +|