Search code examples
csvgraphneo4jcypherload-csv

Can we use more than 1 row in LOAD CSV(neo4j)?


LOAD CSV reads row by row and one can do any kind of operation on that row. Is it possible to use more than one row at a time, for example, say I want to assign a relationship where every i'th row is a friend of (i-1)'th row? Or is it possible to store values of previous rows in some local variables while the LOAD CSV is running?


Solution

  • I don't think referring (i-1) row is possible with LOAD CSV.

    Instead, you can add one column say friendID at the end of each row in CSV that has ID of (i-1) and then you need to do 2 scans over the same CSV.

    Scan-1) This will create the Person nodes (friendID column will not be used)

    Scan-2) This will create the relationships between Person nodes using the friendID column