Predicates are boolean functions that return true or false for a given set of input. They are most commonly used to filter out subgraphs in the WHERE part of a query.

Exists(Property)

exists() returns true if the specified property exists in the node, relationship or map. This is different from the EXISTS clause.

Syntax: exists(property)

Returns:

An agtype boolean

Arguments:

Name Description
property A property from a vertex or edge

Query

  1. SELECT *
  2. FROM cypher('graph_name', $$
  3. MATCH (n)
  4. WHERE exists(n.surname)
  5. RETURN n.first_name, n.last_name
  6. $$) as (first_name agtype, last_name agtype);

Results:

first_name last_name
‘John ‘Smith’
‘Patty’ ‘Patterson’
2 row(s) returned

Exists(Path)

EXISTS(path) returns true if for the given path, there already exists the given path.

  1. SELECT *
  2. FROM cypher('graph_name', $$
  3. MATCH (n)
  4. WHERE exists((n)-[]-({name: 'Willem Defoe'}))
  5. RETURN n.full_name
  6. $$) as (full_name agtype);

Results:

full_name
‘Toby Maguire’
‘Tom Holland’
2 row(s) returned