openCypher icon indicating copy to clipboard operation
openCypher copied to clipboard

Support calling aggregation functions on lists in expressions

Open boggle opened this issue 9 years ago • 3 comments

CIR-2017-183

Cypher has a great set of aggregation functions that can be used to compute aggregate values over multiple result records.

However it currently is not possible to call these aggregation functions on lists in an expression evaluation context. Currently users that need to achieve this usually try to help themselves by using collect, UNWIND, and list comprehensions.

This CIR looks for a better way to achieve this user goal.

Requirements

Proposals should provide a syntax extensions for allowing to call aggregation functions over lists in an expression evaluation context.

boggle avatar Feb 05 '17 12:02 boggle

If we use another syntax for aggregation [CIR2017-188], then using the aggregator name with regular function-call syntax could be used to aggregate over a list argument.

thobe avatar Feb 22 '17 08:02 thobe

Another way to solve this is by scalar subqueries (pending syntax finalization):

RETURN  <(((< UNWIND my_list AS item RETURN sum(item) >)))>

thobe avatar Apr 13 '17 13:04 thobe

There is function reduce() having functionality suitable for min/max/sum/avg. E.g.: reduce( i=0, x IN list | i+x ) is equivalent to sum(list).

trzeci avatar Jun 01 '17 12:06 trzeci