I would like to use LOAD CSV together with CASE. Depending on a value in one of the columns of each line, nodes with varying label should be created. In my example, I am dealing with two labels ("Input" and "Variable"). I tried the following:
LOAD CSV WITH HEADERS FROM 'file:///nodes.csv' AS line
CASE line.Typ
WHEN 'Input' THEN MERGE (n0:Input {name: line.Name})
WHEN 'Variable' THEN MERGE (n0:Variable {name: line.Name})
END
Any suggestions how to solve this task? Error message is
The case statement does not provide that functionality. It is not a control statement, but a method that returns a value.
You have a number of options. You can use the apoc.do.when procedure to do what you tried to do with the case statement.
Another option using pure cypher is to use a series of call subqueries to create the nodes, with one call subquery for each different condition. Here is a code snippet to show you the idea:
call{
with line
with line, line.Typ as type
where type = “Input”
MERGE (:Input {name: line.Name})
}
call
{
with line
with line, line.Typ = “Variable”
MERGE (:Variable {name: line.Name})
}