添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
冷静的咖啡  ·  指针 delete ...·  1 周前    · 
伤情的感冒药  ·  Format Query Results ...·  1 年前    · 
喝醉的烤面包  ·  刺猬索尼克 | PowerA·  1 年前    · 

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

CREATE
  (keanu:Person {name:'Keanu Reeves', age:58, nationality:'Canadian'}),
  (carrie:Person {name:'Carrie Anne Moss', age:55, nationality:'American'}),
  (liam:Person {name:'Liam Neeson', age:70, nationality:'Northern Irish'}),
  (guy:Person {name:'Guy Pearce', age:55, nationality:'Australian'}),
  (kathryn:Person {name:'Kathryn Bigelow', age:71, nationality:'American'}),
  (jessica:Person {name:'Jessica Chastain', age:45, address:''}),
  (theMatrix:Movie {title:'The Matrix'}),
  (keanu)-[:KNOWS]->(carrie),
  (keanu)-[:KNOWS]->(liam),
  (keanu)-[:KNOWS]->(kathryn),
  (kathryn)-[:KNOWS]->(jessica),
  (carrie)-[:KNOWS]->(guy),
  (liam)-[:KNOWS]->(guy),
  (keanu)-[:ACTED_IN]->(theMatrix),
  (carrie)-[:ACTED_IN]->(theMatrix)

The function all() returns true if the predicate holds for all elements in the given list.

null is returned if the list is null or if the predicate evaluates to null for at least one element and does not evaluate to false for any other element.

Syntax:

all(variable IN list WHERE predicate)

Returns:

An expression that returns a list. A single element cannot be explicitly passed as a literal in the cypher statement. However, an implicit conversion will happen for single elements when passing node properties during cypher execution.

variable

A variable that can be used from within the predicate.

predicate

A predicate that is tested against all items in the list.

The function any() returns true if the predicate holds for at least one element in the given list.

null is returned if the list is null , or if the predicate evaluates to null for at least one element and does not evaluate to true for any other element.

Syntax:

any(variable IN list WHERE predicate)

Returns:

An expression that returns a list. A single element cannot be explicitly passed as a literal in the cypher statement. However, an implicit conversion will happen for single elements when passing node properties during cypher execution.

variable

A variable that can be used from within the predicate.

predicate

A predicate that is tested against all items in the list.

This query returns the name property of every Person node, along with a boolean ( true or false ) indicating if those nodes have an ACTED_IN relationship in the graph.

Table 3. Result

The function exists() looks very similar to the expression EXISTS { ... } , but they are not related.

See Using EXISTS subqueries for more information.

The function isEmpty() returns true if the given list or map contains no elements, or if the given string contains no characters.

Syntax:

isEmpty(list)

Returns:

This query returns every Person node in the graph with a set nationality property value (i.e., all Person nodes except for Jessica Chastain ):

Table 4. Result

The name property of each node that has an empty (empty string) address property is returned:

Table 5. Result

The function isEmpty() , like most other Cypher ® functions, returns null if null is passed in to the function. That means that a predicate isEmpty(n.address) will filter out all nodes where the address property is not set. Thus, isEmpty() is not suited to test for null -values. IS NULL or IS NOT NULL should be used for that purpose.

The function none() returns true if the predicate does not hold for any element in the given list.

null is returned if the list is null , or if the predicate evaluates to null for at least one element and does not evaluate to true for any other element.

Syntax:

none(variable IN list WHERE predicate)

Returns:

An expression that returns a list. A single element cannot be explicitly passed as a literal in the cypher statement. However, an implicit conversion will happen for single elements when passing node properties during cypher execution.

variable

A variable that can be used from within the predicate.

predicate

A predicate that is tested against all items in the list.

(:Person {nationality: "Canadian",name: "Keanu Reeves",age: 58})-[:KNOWS]->(:Person {nationality: "American",name: "Carrie Anne Moss",age: 55})

(:Person {nationality: "Canadian",name: "Keanu Reeves",age: 58})-[:KNOWS]->(:Person {nationality: "American",name: "Carrie Anne Moss",age: 55})-[:KNOWS]->(:Person {nationality: "Australian",name: "Guy Pearce",age: 55})

The function single() returns true if the predicate holds for exactly one of the elements in the given list.

null is returned if the list is null , or if the predicate evaluates to null for at least one element and true for max one element.

Syntax:

single(variable IN list WHERE predicate)

Returns:

WHERE n.name = 'Keanu Reeves' AND single(x IN nodes(p) WHERE x.nationality = 'Northern Irish') RETURN p

In every returned path there is exactly one node which the nationality property value Northern Irish :

Table 7. Result

Join us for the biggest graph community conference dedicated to learning how to integrate graph technologies into ML and dev projects.

Save your spot

© 2023 Neo4j, Inc.
Terms | Privacy | Sitemap

Neo4j ® , Neo Technology ® , Cypher ® , Neo4j ® Bloom and Neo4j ® Aura are registered trademarks of Neo4j, Inc. All other marks are owned by their respective companies.

Contact Us →

US: 1-855-636-4532
Sweden +46 171 480 113
UK: +44 20 3868 3223
France: +33 (0) 1 88 46 13 20