Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 28 additions & 7 deletions pages/querying/subquery-expressions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand Down