Skip to content

WHERE clause

Marijn van Wezel edited this page Jan 1, 2023 · 8 revisions

The WHERE clause adds constraints to the patterns in a MATCH or OPTIONAL MATCH clause or filters the results of a WITH clause.

Query::where(bool|BooleanType|(bool|BooleanType)[] $expressions, string $operator = WhereClause::AND): Query

Parameters

  • $expressions : A boolean expression to evaluate, or a non-empty list of boolean expression to evaluate.
  • $operator : The operator with which to unify the given expressions, should be either WhereClause::OR, WhereClause::AND or WhereClause::XOR.

Relevant methods

  • addExpression(bool|BooleanType $expression, string $operator): self : Add an expression to the WHERE clause, potentially unified with the existing clause using $operator.

Examples

Boolean operations

$n = node('Person');
$query = query()
    ->match($n)
    ->where($n->property('name')->equals('Peter'))
    ->returning($n)
    ->build();

$this->assertStringMatchesFormat("MATCH (%s:Person) WHERE (%s.name = 'Peter') RETURN %s", $query);

Filter on node label

$n = node();
$query = query()
    ->match($n)
    ->where($n->labeled('Person'))
    ->returning($n)
    ->build();

$this->assertStringMatchesFormat("MATCH (%s) WHERE %s:Person RETURN %s", $query);

External links