Unique Nodes loaded from CSV file

I have the following simple Cypher script:

LOAD CSV WITH HEADERS FROM "file:///test.csv" AS row FIELDTERMINATOR ';'
merge (n:Subject {code: row.NodeA})
merge (m:Object {code: row.NodeB})
merge (r:Relation {code: row.Relation})
MERGE (n)-[:TO]->(r)
merge (r)-[:TO]->(m)

with the following test.csv:

ID

NodeA

Relation

NodeB

1

AM 4.0

includes

Systemic leadership

2

AM 4.0

is based on

Agile Mindset

My assuption is that the Cypher script should generate unique Nodes n, so only one Node n with Code = NodeA ={AM 4.0} should be generated.

But this is not the case. Also the usage of CONSTRAINT for Code doen't help.

What goes wrong?

Thank you very much for your help!!

Hi @Alfred_Oswald, MERGE creates the node only if it is not existing and in this case it has to only create one node with the label Subject and two nodes with the label [Systematic leadership, Agile Mindset]. The only problem might be coming from you file, if the column NodeA has some extra spaces then it is considered as a different string. From what you have shown here, this might be the only idea that I have.

If you can share more, like some logs of what is happening there, I might be able to help you more.

Dear ninja busymo16, your hint is the solution! Thank you very much!!!