Commonly used Functions

String Functions

match (a) return toUpper(a.firstname);


RETURN left('hello', 3)

RETURN lTrim('   hello')

RETURN replace("hello", "l", "w")

RETURN reverse('hello')

RETURN substring('hello', 1, 3), substring('hello', 2)


RETURN toString(11.5),
toString('already a string'),
toString(true),
toString(date({year:1984, month:10, day:11})) AS dateString,
toString(datetime({year:1984, month:10, day:11, hour:12, minute:31, second:14, millisecond: 341, timezone: 'Europe/Stockholm'})) AS datetimeString,
toString(duration({minutes: 12, seconds: -60})) AS durationString

Aggregation Functions

  • COUNT: Counts the number of items.

    MATCH (n:Student)
    RETURN COUNT(n);
  • MAX and MIN: Find the maximum or minimum of a set of values.

    MATCH (n:Student)-[r:TAKING]->(c)
    RETURN MAX(r.grade), MIN(r.grade);

Date and Time Functions

  • date(): Creates a date from a string or a map.

    RETURN date('2024-03-20');
  • datetime(): Creates a datetime from a string or a map.

    RETURN datetime('2024-03-20T12:00:00');
  • duration.between(): Calculates the duration between two temporal values.

    RETURN duration.between(date('1984-10-11'), date('2024-03-20'));

List Functions

  • COLLECT: Aggregates values into a list.

    MATCH (n:Student)
    RETURN COLLECT(n.firstname);
  • SIZE: Returns the size of a list.

    MATCH (n:Student)
    RETURN COLLECT(n.firstname), SIZE(COLLECT(n.firstname));
  • RANGE: Creates a list containing a sequence of integers.

    RETURN RANGE(1, 10, 2);

Mathematical Functions

  • ABS: Returns the absolute value.

    RETURN ABS(-42);
  • ROUND, CEIL, FLOOR: Round numbers to the nearest integer, up, or down.

    RETURN ROUND(3.14159), CEIL(3.14159), FLOOR(3.14159);

Logical Functions

  • COALESCE: Returns the first non-null value in a list of expressions.

    RETURN COALESCE(NULL, 'first non-null', NULL);

Spatial Functions

  • point: Creates a point in a 2D space (or 3D if you add elevation) which can be used for spatial queries.

    RETURN point({latitude: 37.4847, longitude: -122.148})
  • distance: Calculates the geodesic distance between two points in Meters. Cherryhill to Moorestown. Verify the result https://www.nhc.noaa.gov/gccalc.shtml

    RETURN point.distance(
      point({latitude: 39.94, longitude: -75.01}), 
      point({latitude: 39.97, longitude: -74.96})
    ) / 1609.34 AS distanceInMiles
  • apoc.coll.sort: Sorts a list.

    RETURN apoc.coll.sort(['banana', 'apple', 'cherry'])
  • apoc.map.merge: Merges two maps.

    RETURN apoc.map.merge({name: 'Neo'}, {age: 23})

Last updated