Prev |  | Next

## 13.2. Scalar functions

Scalar functions return a single value.

Figure 13.2. Graph

### 13.2.1. LENGTH

To return or filter on the length of a collection, use the `LENGTH()` function.

Syntax: `LENGTH( collection )`

Arguments:

- collection: An expression that returns a collection

Query.

    MATCH p=(a)-->(b)-->(c)
    WHERE a.name='Alice'
    RETURN length(p)

The length of the path `p` is returned by the query.

Result

length(p)
3 rows
`2`
`2`
`2`

### 13.2.2. TYPE

Returns a string representation of the relationship type.

Syntax: `TYPE( relationship )`

Arguments:

- relationship: A relationship.

Query.

    MATCH (n)-[r]->()
    WHERE n.name='Alice'
    RETURN type(r)

The relationship type of `r` is returned by the query.

Result

type(r)
2 rows
`"KNOWS"`
`"KNOWS"`

### 13.2.3. ID

Returns the id of the relationship or node.

Syntax: `ID( property-container )`

Arguments:

- property-container: A node or a relationship.

Query.

    MATCH (a)
    RETURN id(a)

This returns the node id for three nodes.

Result

id(a)
5 rows
`0`
`1`
`2`
`3`
`4`

### 13.2.4. COALESCE

Returns the first non-`NULL` value in the list of expressions passed to it. In case all arguments are `NULL`, `NULL` will be returned.

Syntax: `COALESCE( expression [, expression]* )`

Arguments:

- expression: The expression that might return NULL.

Query.

    MATCH (a)
    WHERE a.name='Alice'
    RETURN coalesce(a.hairColor, a.eyes)

Result

coalesce(a.hairColor, a.eyes)
1 row
`"brown"`

### 13.2.5. HEAD

`HEAD` returns the first element in a collection.

Syntax: `HEAD( expression )`

Arguments:

- expression: This expression should return a collection of some kind.

Query.

    MATCH (a)
    WHERE a.name='Eskil'
    RETURN a.array, head(a.array)

The first node in the path is returned.

Result

a.array | head(a.array)
--- | ---
1 row
`["one","two","three"]` | `"one"`

### 13.2.6. LAST

`LAST` returns the last element in a collection.

Syntax: `LAST( expression )`

Arguments:

- expression: This expression should return a collection of some kind.

Query.

    MATCH (a)
    WHERE a.name='Eskil'
    RETURN a.array, last(a.array)

The last node in the path is returned.

Result

a.array | last(a.array)
--- | ---
1 row
`["one","two","three"]` | `"three"`

### 13.2.7. TIMESTAMP

`TIMESTAMP` returns the difference, measured in milliseconds, between the current time and midnight, January 1, 1970 UTC. It will return the same value during the whole one query, even if the query is a long running one.

Syntax: `TIMESTAMP()`

Arguments:

Query.

    RETURN timestamp()

The time in milliseconds is returned.

Result

timestamp()
1 row
`1392895902534`

### 13.2.8. STARTNODE

`STARTNODE` returns the starting node of a relationship

Syntax: `STARTNODE( relationship )`

Arguments:

- relationship: An expression that returns a relationship

Query.

    MATCH (x:foo)-[r]-()
    RETURN startNode(r)

Result

startNode(r)
2 rows
`Node[2]{name:"Alice",age:38,eyes:"brown"}`
`Node[2]{name:"Alice",age:38,eyes:"brown"}`

### 13.2.9. ENDNODE

`ENDNODE` returns the end node of a relationship

Syntax: `ENDNODE( relationship )`

Arguments:

- relationship: An expression that returns a relationship

Query.

    MATCH (x:foo)-[r]-()
    RETURN endNode(r)

Result

endNode(r)
2 rows
`Node[3]{name:"Bob",age:25,eyes:"blue"}`
`Node[4]{name:"Charlie",age:53,eyes:"green"}`

Copyright © 2014 Neo Technology

Prev | Up | Next
| Home |