openCypher icon indicating copy to clipboard operation
openCypher copied to clipboard

Provide a way to order lists

Open thobe opened this issue 9 years ago • 3 comments

CIR-2017-190

When collect(...)ing values, it should be possible to order the collected elements.

It would also be nice to be able to (re-)order an existing collection, for instance through the use of comprehension.

thobe avatar Feb 27 '17 13:02 thobe

Idea:

MATCH (p:Person)-[:KNOWS]-(friend) RETURN p.name, collect(friend.name ORDER BY friend.age DESC)

thobe avatar Feb 28 '17 08:02 thobe

Idea for ordering already collected lists:

WITH [1, 0, 5, -3] AS list
WITH [e IN list | e ORDER BY e] AS orderedList
RETURN orderedList

I feel like this fits well with the language in its current form, but it's not very elegant. Perhaps just using DESC and ASC as unary operators could be another alternative:

WITH [1, 0, 5, -3] AS list
WITH list DESC AS orderedList
RETURN orderedList

Mats-SX avatar Feb 28 '17 08:02 Mats-SX

Using ASC or DESC as unary operators could be added as a syntactic sugar. However, in case of a list of nodes, property access needs to be specified to allow sorting, so I see the verbose form as a must have.

jmarton avatar Apr 18 '17 11:04 jmarton