Reputation: 24871
I came across following Cypher example:
RETURN range(0,10)[3]
which outputs 3
.
I was wondering if I can index into arbitrary array something as follows:
MATCH a = [0,2,1,8,9] AS collection
RETURN a[2]
I was expecting it to print 1
since its the number at the index 2 in the collection. But it gives error:
Invalid input '[': expected whitespace, comment
Is this possible to do?
Upvotes: 0
Views: 84
Reputation: 11
The easiest way in you style:
MATCH () WITH [0, 2, 1, 8, 9] AS a LIMIT 1 RETURN a[2]
It is doing the following thing: Match finds the first node but it pushes your constant array into the pipeline (only once because of LIMIT 1) and RETURN gives back the third element.
Upvotes: 1