3.4. Functions

This section contains information on all functions in the Cypher query language.

Note that related information exists in Section 3.2.5, “Operators”.

Most functions in Cypher will return null if an input parameter is null.

Predicate functions

These functions return either true or false for the arguments given.

Function Description

all()

Tests whether a predicate holds for all elements in the list.

any()

Tests whether a predicate holds for at least one element in the list.

exists()

Returns true if a match for the pattern exists in the graph, or the property exists in the node, relationship or map.

none()

Returns true if the predicate holds for no element in the list.

single()

Returns true if the predicate holds for exactly one of the elements in the list.

Scalar functions

These functions return a single value.

Function Description

coalesce()

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

endNode()

Returns the last node of a relationship.

head()

Returns the first element in a list.

id()

Returns the id of the relationship or node.

last()

Returns the last element in a list.

length()

Returns the length of a path.

properties()

If the argument is a node or a relationship, the returned map is a map of its properties.

size()

Returns the number of items in a list.

Size of pattern expression

Returns the number of sub-graphs matching the pattern expression.

Size of string

Returns the size of a string.

startNode()

Returns the first node of a relationship.

timestamp()

Returns the difference, measured in milliseconds, between the current time and midnight, January 1, 1970 UTC.

toBoolean()

Converts the argument to a boolean and returns the result.

toFloat()

Converts the argument to a float and returns the result.

toInteger()

Converts the argument to an integer and returns the result.

type()

Returns a string representation of the relationship type.

Aggregating functions

These functions take multiple values as arguments, and calculate and return an aggregated value from them.

Function Description

avg()

Returns the average of a numeric column.

collect()

Returns a list containing all collected values.

count()

Returns the number of rows.

max()

Returns the highest value in a numeric column.

min()

Returns the lowest value in a numeric column.

percentileCont()

Returns the percentile of a given value over a group using linear interpolation.

percentileDisc()

Returns the nearest value to a given percentile over a group using a rounding method.

stDev()

Returns the standard deviation for a given value over a group for a sample of a population.

stDevP()

Returns the standard deviation for a given value over a group for an entire population.

sum()

Returns the sum of a numeric column.

List functions

These functions return lists of other values. Further details and examples of lists may be found in Section 3.2.8, “Lists”.

Function Description

extract()

Returns a single property, or the value of a function from a list of nodes or relationships.

filter()

Returns all the elements in a list complying with a predicate.

keys()

Returns a list of string representations for the property names of a node, relationship, or map.

labels()

Returns a list of string representations for the labels attached to a node.

nodes()

Returns all nodes in a path.

range()

Returns numerical values in a range.

reduce()

Runs an expression against individual elements of a list, storing the result of the expression in an accumulator.

relationships()/rels()

Returns all relationships in a path.

tail()

Returns all but the first element in a list.

Mathematical functions - numeric

These functions all operate on numerical expressions only, and will return an error if used on any other values.

Function Description

abs()

Returns the absolute value of a number.

ceil()

Returns the smallest integer greater than or equal to the argument.

floor()

Returns the greatest integer less than or equal to the expression.

rand()

Returns a random number in the range from 0 (inclusive) to 1 (exclusive), [0, 1).

round()

Returns the numerical expression, rounded to the nearest integer.

sign()

Returns the signum of a number — zero if the expression is zero, -1 for any negative number, and 1 for any positive number.

Mathematical functions - logarithmic

These functions all operate on numerical expressions only, and will return an error if used on any other values.

Function Description

e()

Returns the base of the natural logarithm, e.

exp()

Returns e^n, where e is the base of the natural logarithm, and n is the value of the argument expression.

log()

Returns the natural logarithm of the expression.

log10()

Returns the common logarithm (base 10) of the expression.

sqrt()

Returns the square root of a number.

Mathematical functions - trigonometric

These functions all operate on numerical expressions only, and will return an error if used on any other values.

All trigonometric functions operate on radians, unless otherwise specified.

Function Description

acos()

Returns the arccosine of the expression.

asin()

Returns the arcsine of the expression.

atan()

Returns the arctangent of the expression.

atan2()

Returns the arctangent2 of a set of coordinates.

cos()

Returns the cosine of the expression.

cot()

Returns the cotangent of the expression.

degrees()

Converts radians to degrees.

haversin()

Returns half the versine of the expression.

pi()

Returns the mathematical constant pi.

radians()

Converts degrees to radians.

sin()

Returns the sine of the expression.

tan()

Returns the tangent of the expression.

String functions

These functions are used to manipulate strings or to create a string representation of another value.

Function Description

left()

Returns a string containing the left n characters of the original string.

lTrim()

Returns the original string with whitespace removed from the left side.

replace()

Returns a string with the search string replaced by the replace string, replacing all occurrences.

reverse()

Returns the original string reversed.

right()

Returns a string containing the right n characters of the original string.

rTrim()

Returns the original string with whitespace removed from the right side.

split()

Returns the sequence of strings which are delimited by split patterns.

substring()

Returns a substring of the original, with a 0-based index start and length.

toLower()

Returns the original string in lowercase.

toString()

Converts the argument to a string.

toUpper()

Returns the original string in uppercase.

trim()

Returns the original string with whitespace removed from both sides.

Spatial functions

These functions are used to specify points in a 2D coordinate system and to calculate the geodesic distance between two points.

Function Description

distance()

Returns a floating point number representing the geodesic distance between any two given points.

point() - cartesian 2D

Returns a point object, given two coordinate values in the cartesian coordinate system.

point() - WGS 84

Returns a point object, given two coordinate valuesin the WGS 84 coordinate system.