Prev |  | Next

## 16.11. Functions

Here is a list of the functions in Cypher, seperated into three different sections: Predicates, Scalar functions and Aggregated functions

Graph

### 16.11.1. Predicates

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.

### 16.11.2. ALL

Tests the predicate closure to see if all items in the iterable match.

Syntax: `ALL(identifier in iterable : predicate)`

Arguments:

- iterable: An array property, or an iterable symbol, or an iterable function.
- symbol: The closure will have a symbol introduced in it’s context. Here you decide which symbol to use. If you leave the symbol out, the default symbol `_` (underscore) will be used.
- predicate: A predicate that is tested against all items in iterable

Query

    START a=node(3), b=node(1)
    MATCH p=a-[*1..3]->b
    WHERE all(x in nodes(p) : x.age > 30)
    RETURN p

All nodes in the path.

Result

p
1 rows, 2 ms
`(3)--[KNOWS,1]-->(5)--[KNOWS,3]-->(1)`

### 16.11.3. ANY

Tests the predicate closure to see if at least one item in the iterable match.

Syntax: `ANY(identifier in iterable : predicate)`

Arguments:

- iterable: An array property, or an iterable symbol, or an iterable function.
- symbol: The closure will have a symbol introduced in it’s context. Here you decide which symbol to use. If you leave the symbol out, the default symbol `_` (underscore) will be used.
- predicate: A predicate that is tested against all items in iterable

Query

    START a=node(3)
    MATCH p=a-[*1..3]->b
    WHERE any(x in nodes(p) : x.eyes = "blue")
    RETURN p

All nodes in the path.

Result

p
3 rows, 2 ms
`(3)--[KNOWS,0]-->(4)`
`(3)--[KNOWS,0]-->(4)--[KNOWS,2]-->(1)`
`(3)--[KNOWS,0]-->(4)--[MARRIED,4]-->(2)`

### 16.11.4. NONE

Tests the predicate closure to see if no items in the iterable match. If even one matches, the function returns false.

Syntax: `NONE(identifier in iterable : predicate)`

Arguments:

- iterable: An array property, or an iterable symbol, or an iterable function.
- symbol: The closure will have a symbol introduced in it’s context. Here you decide which symbol to use. If you leave the symbol out, the default symbol `_` (underscore) will be used.
- predicate: A predicate that is tested against all items in iterable

Query

    START n=node(3)
    MATCH p=n-[*1..3]->b
    WHERE NONE(x in nodes(p) : x.age = 25)
    RETURN p

All nodes in the path.

Result

p
2 rows, 3 ms
`(3)--[KNOWS,1]-->(5)`
`(3)--[KNOWS,1]-->(5)--[KNOWS,3]-->(1)`

### 16.11.5. SINGLE

Returns true if the closure predicate matches exactly one of the items in the iterable.

Syntax: `SINGLE(identifier in iterable : predicate)`

Arguments:

- iterable: An array property, or an iterable symbol, or an iterable function.
- symbol: The closure will have a symbol introduced in it’s context. Here you decide which symbol to use. If you leave the symbol out, the default symbol `_` (underscore) will be used.
- predicate: A predicate that is tested against all items in iterable

Query

    START n=node(3)
    MATCH p=n-->b
    WHERE SINGLE(var in nodes(p) : var.eyes = "blue")
    RETURN p

All nodes in the path.

Result

p
1 rows, 1 ms
`(3)--[KNOWS,0]-->(4)`

### 16.11.6. Scalar functions

Scalar functions return a single value.

### 16.11.7. LENGTH

To return or filter on the length of a path, use the special property LENGTH

Syntax: `LENGTH( iterable )`

Arguments:

- iterable: An iterable, value or function call

Query

    START a=node(3)
    MATCH p=a-->b-->c
    RETURN length(p)

The length of the path p.

Result

LENGTH(p)
3 rows, 2 ms
`2`
`2`
`2`

### 16.11.8. TYPE

Returns a string representation of the relationship type.

Syntax: `TYPE( relationship )`

Arguments:

- relationship: A relationship

Query

    START n=node(3)
    MATCH (n)-[r]->()
    RETURN type(r)

The relationship type of r.

Result

TYPE(r)
2 rows, 1 ms
`KNOWS`
`KNOWS`

### 16.11.9. ID

Returns the id of the relationship or node

Syntax: `ID( property-container )`

Arguments:

- property-container: A node or a relationship

Query

    START a=node(3, 4, 5)
    RETURN ID(a)

The node id for three nodes.

Result

ID(a)
3 rows, 0 ms
`3`
`4`
`5`

### 16.11.10. Iterable functions

Iterable functions return an iterable of things - nodes in a path, and so on.

### 16.11.11. NODES

Returns all nodes in a path

Syntax: `NODES( path )`

Arguments:

- path: A path

Query

    START a=node(3), c=node(2)
    MATCH p=a-->b-->c
    RETURN NODES(p)

All the nodes in the path p.

Result

NODES(p)
1 rows, 2 ms
`List(Node[3], Node[4], Node[2])`

### 16.11.12. RELATIONSHIPS

Returns all relationships in a path

Syntax: `RELATIONSHIPS( path )`

Arguments:

- path: A path

Query

    START a=node(3), c=node(2)
    MATCH p=a-->b-->c
    RETURN RELATIONSHIPS(p)

All the nodes in the path p.

Result

RELATIONSHIPS(p)
1 rows, 2 ms
`List(Relationship[0], Relationship[4])`

Copyright © 2011 Neo Technology

Prev | Up | Next
| Home |