Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
09-29-2021 03:13 AM
It's a sort of regular problem but I still cannot figure out the solution if not to use any plugin-in libraries.
Here is code snippet as follows, and I just iterate over rows and project each cell onto the corresponding header.
load csv with headers from "file:///data.csv" as row
CREATE (n:Test)
WITH row, n
UNWIND keys(row) AS k
with row, k, n
SET n += { k: row[k]}
The question is how to set a variable k
as key within properties of node.
Unfortunately, I always get literally key as "k" and sequentially overwrite the previous result from the SET clause.
Thanks for guys time for reading.
Solved! Go to Solution.
09-29-2021 04:12 AM
Hello @silenceliang and welcome to the Neo4j community
It is not possible to create a dictionary dynamically only in Cypher. You will have to use the function apoc.load.csv() in the APOC plugin. This function allows you get each row as a map.
CALL apoc.load.csv('data.csv')
YIELD lineNo, map, list
CREATE (n:Test)
SET n += map
Regards,
Cobra
09-29-2021 04:12 AM
Hello @silenceliang and welcome to the Neo4j community
It is not possible to create a dictionary dynamically only in Cypher. You will have to use the function apoc.load.csv() in the APOC plugin. This function allows you get each row as a map.
CALL apoc.load.csv('data.csv')
YIELD lineNo, map, list
CREATE (n:Test)
SET n += map
Regards,
Cobra
09-29-2021 04:59 AM
Hi Cobra,
Thanks for the quick reply!
I was expected to implement such a handy function by naive cypher syntax before.
Appreciate a lot I will try to use APOC plugins and go on exploring neo4j !
Sincerely,
silence
All the sessions of the conference are now available online