apoc.coll.avgDuration
Function APOC Full
apoc.coll.avgDuration([duration('P2DT3H'), duration('PT1H45S'), …]) - returns the average of a list of duration values
Usage Examples
The apoc.coll.avgDuration
works similar to the avg()
function,
but it’s not an aggregate function and takes a list of durations as an argument.
For example:
WITH [duration('P2DT4H1S'), duration('PT1H1S'), duration('PT1H6S'), duration('PT1H5S')] AS durations
RETURN apoc.coll.avgDuration(durations) AS value
value |
---|
PT13H45M3.25S |
In case of null or empty list, a null
result will be returned:
RETURN apoc.coll.avgDuration([]) AS output;
RETURN apoc.coll.avgDuration(null) AS output;
output |
---|
null |
In case a non-duration list is passed, a Type mismatch
error will be thrown:
RETURN apoc.coll.avgDuration([1,2,3]) AS value;
Type mismatch: expected List<Duration> but was List<Integer> |
While in case a list with all duration values is not passed, a TypeError
will be thrown:
RETURN apoc.coll.avgDuration([duration('PT1H1S'),2,3]) AS output;
Can’t coerce `Long(2)` to Duration |