Addind a relationship with multiple properties

Hi there,
I want to add a relationship and use multiple properties.
I´m having trouble finding the right query to make it work.

These were my approaches but both won't work. First has problem with the second property and won't add it, only one is not problem.
Second won't work at all. Somebody knows what to do?

LOAD CSV WITH HEADERS FROM 'file:///csv/politics.csv' AS row
MATCH (c:Country {code: row.country}), (p:Politics {government: row.government})
WHERE row.wasdependent IS NOT NULL AND row.dependent IS NOT NULL
MERGE (c)-[:HAS_POLITICAL_INFO {wasdependent: row.wasdependent, dependent: row.dependent}]->(p);

LOAD CSV WITH HEADERS FROM 'file:///csv/politics.csv' AS row
WITH row WHERE row.wasdependent IS NOT NULL AND row.dependent IS NOT NULL
MATCH (c:Country {code: row.country})
MATCH (p:Politics {government: row.government})
MERGE (c)-[r:HAS_POLITICAL_INFO]->(p)
SET r.wasdependent = row.wasdependen, r.dependent = row.dependent;

@TornadoJoe

What version of Neo4j?
Regarding

Second won't work at all. Somebody knows what to do?

do you get an error? does it hang? or you get unexpected results?
what does

LOAD CSV WITH HEADERS FROM 'file:///csv/politics.csv' AS row return row limit 5;

report?

Both should work, but they may produce different outcomes.

The first approach is specifying the relationship properties in the merge, so the relationship will be created with these properties even one already exists with different property values. The outcome could be multiple relationships.

The second approach does not specify the properties in the merge, so the relationship will only be created if one doesn't exits. The properties will be set on the new relationship or the existing one.

What is the behavior you are experiencing that is not what you don’t want?

LOAD CSV WITH HEADERS FROM 'file:///csv/politics.csv' AS row
WITH row WHERE row.wasdependent IS NOT NULL AND row.dependent IS NOT NULL
MATCH (c:Country {code: row.country})
MATCH (p:Politics {government: row.government})
MERGE (c)-[r:HAS_POLITICAL_INFO]->(p)
SET r.wasdependent = row.wasdependen, r.dependent = row.dependent;

Not sure if it's just a typo here or in your query in general but when you do the last SET the row.wasdependen is missing a t at the end.

Not sure if that is your issue but typos can sometimes lead to unexpected behaviours :person_shrugging: So it might be a good idea to look over both your query and your file to confirm you have the same spelling for all columns.

Other than that, I agree with Dana about trying out just the LOAD CSV parts to confirm you get the expected values from that to confirm it isn't the input data that is causing the issue.

LOAD CSV WITH HEADERS FROM 'file:///csv/politics.csv' AS row
WITH row WHERE row.wasdependent IS NOT NULL AND row.dependent IS NOT NULL
RETURN row
LIMIT 5

And if you want you can continue the slight debugging by trying to add the MATCH next, and just step by step trying to find where the issue comes from.

LOAD CSV WITH HEADERS FROM 'file:///csv/politics.csv' AS row
WITH row WHERE row.wasdependent IS NOT NULL AND row.dependent IS NOT NULL
MATCH (c:Country {code: row.country})
MATCH (p:Politics {government: row.government})
RETURN c, p
LIMIT 5