Can I conditionally execute a set of MERGEs?

In the topic How many statements can I drive from one CSV LOAD?, @glilienfield shows me that I CAN have multiple statements for the same LOAD.

So, for this particular load, we have the following:
WITH some preliminary global variables
LOAD the CSV
Execute some MATCHes to gather the variables we'll need later
Execute the first set of MERGEs to create some nodes and relationships (based on some CSV columns)
Execute a second set of MERGES to create related nodes and relationships (based on the same column set).
Execute a third set of MERGES to create related nodes and relationships (based on a different column set).

My problem is that the third set of columns is NOT always present (i.e. the values returned are NULL). I initially thought, "that's no problem, the third set of MERGEs will fail, and the specific nodes and relationships won't be created".

But that's NOT what happens! The entire LOAD fails, and nothing is created!

I would like to conditionalise the execution of the third set of MERGEs based on the fact that the returned column value is NULL. Is that possible? The only conditionalisation I know (as a newbie) is CASE, but this is a subordinate clause to a higher-level statement. Have I understood that correctly?

TIA,
Paolo

You can use a ‘call subquery’ or an Alice procedure. Use apoc.do.when when you want to conditionally write something.

There is apoc.when if you want a conditional read.

Or

Can you post the query?

Thanks, @glilienfield,
I'll give them a try!
At this stage, I'm not sure what posting the query would yield. If I can't get things to work, I'll post it.

It's definitely a new paradigm for me, doing many things via external libraries.

Paolo

I can try to solve the issue if I can see the query.

The conditionalization worked (using apoc.do.case)! Although it seems a bit "clunky" (at least how we've done it)

The queries are in a 400-line "script" (although it does set up the nodes and relationships with an associated CSV file).

What's the best way to send them to you?

Paolo