Neo4j Functions

Aggregating functions

count(\*)

The number of matching rows.

count(variable)

The number of non-null values.

count(DISTINCT variable)

All aggregating functions also take the DISTINCT operator, which removes duplicates from the values.

collect(n.property)

List from the values, ignores null.

sum(n.property)

Sum numerical values. Similar functions are avg(), min(), max().

percentileDisc(n.property, $percentile)

Discrete percentile. Continuous percentile is percentileCont(). The percentile argument is from 0.0 to 1.0.

stDev(n.property)

Standard deviation for a sample of a population. For an entire population use stDevP().

Relationship functions

type(a_relationship)

String representation of the relationship type.

startNode(a\_relationship)

Start node of the relationship.

endNode(a\_relationship)

End node of the relationship.

id(a\_relationship)

The internal id of the relationship.

String functions

toString($expression)

String representation of the expression.

replace($original, $search, $replacement)

Replace all occurrences of search with replacement. All arguments must be expressions.

substring($original, $begin, $subLength)

Get part of a string. The subLength argument is optional.

left($original, $subLength),
  right($original, $subLength)

The first part of a string. The last part of the string.

trim($original), lTrim($original),
  rTrim($original)

Trim all whitespace, or on the left or right side.

toUpper($original), toLower($original)

UPPERCASE and lowercase.

split($original, $delimiter)

Split a string into a list of strings.

reverse($original)

Reverse a string.

size($string)

Calculate the number of characters in the string.

Mathematical functions

abs($expr)

The absolute value.

rand()

Returns a random number in the range from 0 (inclusive) to 1 (exclusive), [0,1). Returns a new value for each call. Also useful for selecting a subset or random ordering.

round($expr)

Round to the nearest integer; ceil() and floor() find the next integer up or down.

sqrt($expr)

The square root.

sign($expr)

0 if zero, -1 if negative, 1 if positive.

sin($expr)

Trigonometric functions also include cos(), tan(), cot(), asin(), acos(), atan(), atan2(), and haversin(). All arguments for the trigonometric functions should be in radians, if not otherwise specified.

degrees($expr), radians($expr), pi()

Converts radians into degrees; use radians() for the reverse, and pi() for π.

log10($expr), log($expr), exp($expr), e()

Logarithm base 10, natural logarithm, e to the power of the parameter, and the value of e.

Duration functions

duration("P1Y2M10DT12H45M30.25S")

Returns a duration of 1 year, 2 months, 10 days, 12 hours, 45 minutes and 30.25 seconds.

duration.between($date1,$date2)

Returns a duration between two temporal instances.

WITH duration("P1Y2M10DT12H45M") AS d
RETURN d.years, d.months, d.days, d.hours, d.minutes

Returns 1 year, 14 months, 10 days, 12 hours and 765 minutes.

WITH duration("P1Y2M10DT12H45M") AS d
RETURN d.years, d.monthsOfYear, d.days, d.hours, d.minutesOfHour

Returns 1 year, 2 months, 10 days, 12 hours and 45 minutes.

date("2015-01-01") + duration("P1Y1M1D")

Returns a date of 2016-02-02. It is also possible to subtract durations from temporal instances.

duration("PT30S") * 10

Returns a duration of 5 minutes. It is also possible to divide a duration by a number.

Temporal functions

date("2018-04-05")

Returns a date parsed from a string.

localtime("12:45:30.25")

Returns a time with no time zone.

time("12:45:30.25+01:00")

Returns a time in a specified time zone.

localdatetime("2018-04-05T12:34:00")

Returns a datetime with no time zone.

datetime("2018-04-05T12:34:00[Europe/Berlin]")

Returns a datetime in the specified time zone.

datetime({epochMillis: 3360000})

Transforms 3360000 as a UNIX Epoch time into a normal datetime.

date({year: $year, month: $month, day: $day})

All of the temporal functions can also be called with a map of named components. This example returns a date from year, month and day components. Each function supports a different set of possible components.

datetime({date: $date, time: $time})

Temporal types can be created by combining other types. This example creates a datetime from a date and a time.

date({date: $datetime, day: 5})

Temporal types can be created by selecting from more complex types, as well as overriding individual components. This example creates a date by selecting from a datetime, as well as overriding the day component.

WITH date("2018-04-05") AS d
RETURN d.year, d.month, d.day, d.week, d.dayOfWeek

Accessors allow extracting components of temporal types.

Comments