## 14.2. Scalar functions

14.2.1. LENGTH
14.2.2. TYPE
14.2.3. ID
14.2.4. COALESCE
14.2.6. LAST
14.2.7. TIMESTAMP

Scalar functions return a single value.

### 14.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.

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

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

Result

length(p)
3 rows

`2`

`2`

`2`

Try this query live. (1) {"age":54,"eyes":"brown","name":"D"} (2) {"age":41,"array":["one","two","three"],"eyes":"blue","name":"E"} (3) {"age":38,"eyes":"brown","name":"A"} (4) {"age":25,"eyes":"blue","name":"B"} (5) {"age":53,"eyes":"green","name":"C"} (3)-[:KNOWS]->(4) {} (3)-[:KNOWS]->(5) {} (4)-[:KNOWS]->(1) {} (4)-[:MARRIED]->(2) {} (5)-[:KNOWS]->(1) {} start a=node(3) match p=a-->b-->c return length(p)

### 14.2.2. 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` is returned by the query.

Result

type(r)
2 rows

`"KNOWS"`

`"KNOWS"`

Try this query live. (1) {"age":54,"eyes":"brown","name":"D"} (2) {"age":41,"array":["one","two","three"],"eyes":"blue","name":"E"} (3) {"age":38,"eyes":"brown","name":"A"} (4) {"age":25,"eyes":"blue","name":"B"} (5) {"age":53,"eyes":"green","name":"C"} (3)-[:KNOWS]->(4) {} (3)-[:KNOWS]->(5) {} (4)-[:KNOWS]->(1) {} (4)-[:MARRIED]->(2) {} (5)-[:KNOWS]->(1) {} start n=node(3) match (n)-[r]->() return type(r)

### 14.2.3. 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)```

This returns the node id for three nodes.

Result

ID(a)
3 rows

`3`

`4`

`5`

Try this query live. (1) {"age":54,"eyes":"brown","name":"D"} (2) {"age":41,"array":["one","two","three"],"eyes":"blue","name":"E"} (3) {"age":38,"eyes":"brown","name":"A"} (4) {"age":25,"eyes":"blue","name":"B"} (5) {"age":53,"eyes":"green","name":"C"} (3)-[:KNOWS]->(4) {} (3)-[:KNOWS]->(5) {} (4)-[:KNOWS]->(1) {} (4)-[:MARRIED]->(2) {} (5)-[:KNOWS]->(1) {} start a=node(3, 4, 5) return ID(a)

### 14.2.4. COALESCE

Returns the first non-`null` value in the list of expressions passed to it.

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

Arguments:

• expression: The expression that might return null.

Query.

```START a=node(3)
RETURN coalesce(a.hairColour?, a.eyes?)```

Result

coalesce(a.hairColour?, a.eyes?)
1 row

`"brown"`

Try this query live. (1) {"age":54,"eyes":"brown","name":"D"} (2) {"age":41,"array":["one","two","three"],"eyes":"blue","name":"E"} (3) {"age":38,"eyes":"brown","name":"A"} (4) {"age":25,"eyes":"blue","name":"B"} (5) {"age":53,"eyes":"green","name":"C"} (3)-[:KNOWS]->(4) {} (3)-[:KNOWS]->(5) {} (4)-[:KNOWS]->(1) {} (4)-[:MARRIED]->(2) {} (5)-[:KNOWS]->(1) {} start a=node(3) return coalesce(a.hairColour?, a.eyes?)

`HEAD` returns the first element in a collection.

Syntax: `HEAD( expression )`

Arguments:

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

Query.

```START a=node(2)

The first node in the path is returned.

Result

1 row

`["one","two","three"]`

`"one"`

Try this query live. (1) {"age":54,"eyes":"brown","name":"D"} (2) {"age":41,"array":["one","two","three"],"eyes":"blue","name":"E"} (3) {"age":38,"eyes":"brown","name":"A"} (4) {"age":25,"eyes":"blue","name":"B"} (5) {"age":53,"eyes":"green","name":"C"} (3)-[:KNOWS]->(4) {} (3)-[:KNOWS]->(5) {} (4)-[:KNOWS]->(1) {} (4)-[:MARRIED]->(2) {} (5)-[:KNOWS]->(1) {} start a=node(2) return a.array, head(a.array)

### 14.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.

```START a=node(2)
RETURN a.array, last(a.array)```

The last node in the path is returned.

Result

a.arraylast(a.array)
1 row

`["one","two","three"]`

`"three"`

Try this query live. (1) {"age":54,"eyes":"brown","name":"D"} (2) {"age":41,"array":["one","two","three"],"eyes":"blue","name":"E"} (3) {"age":38,"eyes":"brown","name":"A"} (4) {"age":25,"eyes":"blue","name":"B"} (5) {"age":53,"eyes":"green","name":"C"} (3)-[:KNOWS]->(4) {} (3)-[:KNOWS]->(5) {} (4)-[:KNOWS]->(1) {} (4)-[:MARRIED]->(2) {} (5)-[:KNOWS]->(1) {} start a=node(2) return a.array, last(a.array)

### 14.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.

```START n=node(1)
RETURN timestamp()```

The time in milliseconds.

Result

timestamp()
1 row

`1369048555846`

Try this query live. (1) {"age":54,"eyes":"brown","name":"D"} (2) {"age":41,"array":["one","two","three"],"eyes":"blue","name":"E"} (3) {"age":38,"eyes":"brown","name":"A"} (4) {"age":25,"eyes":"blue","name":"B"} (5) {"age":53,"eyes":"green","name":"C"} (3)-[:KNOWS]->(4) {} (3)-[:KNOWS]->(5) {} (4)-[:KNOWS]->(1) {} (4)-[:MARRIED]->(2) {} (5)-[:KNOWS]->(1) {} start n=node(1) return timestamp()