Empty output in subquery CALL leads to null output

Hi, I recently found some behaviour which confuses me, furthermore I haven't notice such things before neo4j 4.4.

When I do cypher

CALL {
    UNWIND ["a", "b", "c"] as arr1
    RETURN arr1 as include
}
WITH include
RETURN include

I obviously have "a", "b", "c" output.

Then if I do

CALL {
    UNWIND ["a", "b", "c"] as arr1
    RETURN arr1 as include
}
CALL {
    UNWIND ["a"] as arr2
    RETURN arr2 as exclude
}
WITH include, exclude
WHERE include<>exclude
RETURN include

I also have assumed output "b","c"

Weird things starts when second call returns empty set.
Hence cypher

CALL {
    UNWIND ["a", "b", "c"] as arr1
    RETURN arr1 as include
}
CALL {
    UNWIND [] as arr2
    RETURN arr2 as exclude
}
WITH include, exclude
WHERE include<>exclude
RETURN include

Returns nothing. Also if we ignore second call like

CALL {
    UNWIND ["a", "b", "c"] as arr1
    RETURN arr1 as include
}
CALL {
    UNWIND [] as arr2
    RETURN arr2 as exclude
}
WITH include
RETURN include

We also have nothing.

I understand that I use cypher maybe not in most canonical way, but can that be some sort of a bug or something ?

What you are observing is expected. The subquery results are appended to the outer query’s result. As such, when your subquery produces no results, the total result is also no result. Just as what would happen if you had two sequential matches and the second produced no match.

1 Like

Hi @glilienfield
thank you for the response :slight_smile:

1 Like