WITH clause, via simple projections (e.g. WITH n, m), or via WITH * (which imports all bound variables). The variables returned from a subquery may not override existing variables in the outer scope.
The CALL {} clause may be used for numerous purposes, such as: Post-UNION processing, local environment for aggregations and actions on every input row, efficient operations using a limited namespace (via imports) and performing side-effects using non-returning subqueries. Let’s see some examples.
- Post-
UNIONprocessing.
of_interest property to true (to keep monitoring the ‘interesting’ items) using post-UNION processing:
UNION processing to perform aggregations over differently-matched entities. For example, we can count the number of customers and vendors that a store interacts with:
- Local environment for aggregations and actions on every input row.
- Side-effects.
Frequently Asked Questions
What is a CALL \{\} subquery?
What is a CALL \{\} subquery?
CALL {} allows local execution of a subquery for each input row. It enables post-UNION processing, isolated aggregations, and side-effects within a larger query.
How do I import variables into a CALL \{\} subquery?
How do I import variables into a CALL \{\} subquery?
Variables from the outer scope must be imported via an opening
WITH clause inside the subquery, e.g. CALL { WITH n MATCH (n)-[r]->() RETURN count(r) AS rels }. You can also use WITH * to import all bound variables.Can CALL \{\} change the number of result rows?
Can CALL \{\} change the number of result rows?
A returning subquery (with RETURN) can change the row count. A non-returning subquery (without RETURN) preserves the same number of rows, making it ideal for side-effects.
Can I use UNION inside CALL \{\}?
Can I use UNION inside CALL \{\}?
Yes. CALL {} supports post-UNION processing, allowing you to combine results from multiple MATCH patterns and then apply further operations like aggregation or SET on the unified results.