RETURN apoc.coll.max([1,2,3,4,5]) result is NULL?

Neo4j 4.0.3
APOC apoc-
Neo4j Browser version: 4.0.5

As part of an analysis process I get 5 (dirty) collections mixed with numbers, text ans NULLs. I'd like to find the maximum number over all 5 collections. Therefore I did something like
<RETURN apoc.coll.max([0]++[1,2,3,4,5,6]+[7,0]+["ABC"]+) > ==> 7 (fine)

Unfortunately some of the collections have NULL values
<return apoc.coll.max([NULL]+[NULL]+[NULL]+[0,1,2]) > ==> 2 (fine)
<return apoc.coll.max([0,1,2]+[NULL])> ==> 2 (fine)

<return apoc.coll.max([NULL]+[NULL]+[NULL]+[0,1,2]+[NULL]) > ==> NULL

afterwords executing again
<return apoc.coll.max([0,1,2]) > ==> NULL

The only chance to get rid of this NULL is to restart the database

Additional to this:
<apoc.coll.max([""]++[1,2,3,4,5,6]+[7,0]+["ABC"]+)> ==> "ABC"
I would like to have the control, that the apoc.coll.max evaluates only numeric values and not occasionally text.

Hello @klaus.bermuth :slight_smile:

You could use a comprehension list with a CASE to clean your list to make sure to have only integers :slight_smile:



There's a bug in versions before 4.0.4 with respect to how apoc.coll.min and apoc.coll.max work. If you bump your Neo4j version that should sort it out.

See the note on the APOC releases page about this issue -

1 Like