Skip to content

CALL {} (subquery) clause

Marijn van Wezel edited this page Dec 9, 2022 · 8 revisions

The CALL {} clause evaluates a subquery that returns some values. It 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

Parameters

  • $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 to Variable objects.

Relevant methods

  • withSubQuery(Query $subQuery): self: Sets the query to call. This overwrites any previously set sub-query.
  • addWithVariable(Pattern|string|Variable ...$variables): self: Add one or more variables to include in the WITH clause.

Examples

$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);

External links

Clone this wiki locally