From e11a1b49122d4120233c4442e92d9b7a01fa2195 Mon Sep 17 00:00:00 2001 From: imilinovic Date: Thu, 10 Sep 2026 12:47:03 +0200 Subject: [PATCH] docs: the bare pattern shorthand takes what a MATCH pattern takes The page stated two rules that no longer hold: that the shorthand's pattern cannot introduce names of its own, and that it holds a pattern and nothing else so a filter needs the `MATCH` form. It now takes a variable it declares itself, a trailing `WHERE`, a comma-separated list, a named path and a lone node. The worked example is the filter the old text used to send to the `MATCH` form, written as the shorthand, with output from the page's own dataset. `COLLECT` still has no shorthand. --- pages/querying/subquery-expressions.mdx | 35 ++++++++++++++++++++----- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/pages/querying/subquery-expressions.mdx b/pages/querying/subquery-expressions.mdx index 229b931b8..7cbeae4bc 100644 --- a/pages/querying/subquery-expressions.mdx +++ b/pages/querying/subquery-expressions.mdx @@ -402,9 +402,8 @@ Output: ### The bare pattern shorthand `EXISTS` and `COUNT` accept a bare pattern in place of a full body, which is a -shorter way to write a check or a count over one pattern. The pattern cannot -introduce names of its own — a variable already bound outside may appear in it, -and acts as a join: +shorter way to write a check or a count over one pattern. A variable already +bound outside may appear in it, and acts as a join: ```cypher MATCH (p:Person) @@ -427,10 +426,32 @@ Output: +---------+-------+---------+ ``` -The shorthand holds a pattern and nothing else, so a filter or any other clause -needs the `MATCH` form — `COUNT { MATCH (p)-[r:KNOWS]->() WHERE r.since < 2015 }`. -`COLLECT` has no shorthand, since a bare pattern returns no column for it to -gather. +The shorthand takes everything a `MATCH` pattern takes: a variable it declares +itself, a trailing `WHERE`, several patterns separated by commas, a named path, +and a pattern holding only a node. + +```cypher +MATCH (p:Person) +RETURN p.name AS name, + COUNT { (p)-[r:KNOWS]->(f:Person) WHERE r.since < 2015 } AS early +ORDER BY name; +``` + +Output: + +```nocopy ++---------+-------+ +| name | early | ++---------+-------+ +| "Alice" | 1 | +| "Bob" | 0 | +| "Carol" | 0 | +| "Dave" | 0 | ++---------+-------+ +``` + +Any other clause still needs the `MATCH` form. `COLLECT` has no shorthand, since +a bare pattern returns no column for it to gather. ### Correlation with the enclosing query