-
Notifications
You must be signed in to change notification settings - Fork 5
CALL {} (subquery) clause
Marijn van Wezel edited this page Dec 8, 2022
·
8 revisions
The [CALL](https://neo4j.com/docs/cypher-manual/current/clauses/call-subquery/)
clause accepts a query and a list of values to include in the WITH clause for correlation.
Query::call(callable|Query $query, Pattern|string|Variable|(Pattern|string|Variable)[] $variables = []): Query
-
$query
: Either a decorator taking a Query instance, or a Query instance. -
$variables
: The variables or patterns to include in the WITH clause. Variable names given as strings will automatically be converted toVariable
objects.
$query = Query::new()
->call(static function (Query $query) {
$query->create(Query::node("Person"));
})
->build();
$this->assertSame("CALL { CREATE (:Person) }", $query);
$subQuery = Query::new()->create(Query::node("Person"));
$query = Query::new()
->call($subQuery)
->build();
$this->assertSame("CALL { CREATE (:Person) }", $query);
$person = Query::variable();
$query = Query::new()
->match(Query::node('Person')->withVariable($person))
->call(static function (Query $query) use ($person) {
$query->remove($person->labeled('Person'));
}, [$person])
->build();
$this->assertStringMatchesFormat("MATCH (%s:Person) CALL { WITH %s REMOVE %s:Person }", $query);