Saurabh Mittal
Saurabh Mittal

Reputation: 13

Neo4J Cypher - How to perform IN clause operations on a list of lists

In Neo4J, for a simple IN clause check, one can simply do e.g.:

itemList = [i1,i2,i3]

but how to perform an IN operation on list of lists, e.g.

I need to use the operation in conjunction with CASE WHEN, e.g.

CASE WHEN i1 IN itemLists THEN true

Upvotes: 1

Views: 269

Answers (3)

InverseFalcon
InverseFalcon

Reputation: 30407

You can use the any() and all() list predicates for this, depending on what you need.

So to check if a value is in any of the lists present you can use:

any(list in itemLists WHERE i1 IN list)

Upvotes: 2

Dave Bennett
Dave Bennett

Reputation: 11216

You could just add the lists togerther if you want.

WITH 'i1' AS tester 
, ['i1','i2','i3'] AS list1
, ['i4','i5','i6'] AS list2
, ['i7','i8','i9'] AS list3
RETURN CASE 
  WHEN tester IN (list1 + list2 + list3) THEN true
  ELSE false
END AS in_list

Upvotes: 0

logisima
logisima

Reputation: 7478

Your case / when / in solution works, but you can also try to flatten your array and then used the in.

Example : x in reduce(s = [], list IN itemLists | s + list)

Upvotes: 1

Related Questions