12.7. Scalar functions

12.7.1. LENGTH
12.7.2. TYPE
12.7.3. ID
12.7.4. COALESCE
12.7.5. HEAD
12.7.6. LAST
12.7.7. TIMESTAMP

Scalar functions return a single value.

Figure 12.6. Graph


12.7.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


12.7.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"


12.7.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

1

2

3

4

5


12.7.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. 

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

Result

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

"brown"


12.7.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.arrayhead(a.array)
1 row

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

"one"


12.7.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.arraylast(a.array)
1 row

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

"three"


12.7.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

1366592620908