LOAD CSV WITH HEADERS FROM 'https://neo4j.com/docs/cypher-manual/3.5/csv/artists-with-headers.csv' AS line
CREATE (:Artist { name: line[0], year: toInteger(line[1])})
我们在使用上面load csv命令导入数据的时候,可能会遇到下面的错误信息:
Neo.ClientError.Statement.TypeError: Expected Long(0) to be a org.neo4j.values.storable.TextValue, but it was a org.neo4j.values.storable.LongValue
这是因为 load csv 命令加载csv文件时,如果文件无列名,则使用列序号索引是没问题的·,即下面这种用法没问题。
LOAD CSV FROM 'https://neo4j.com/docs/cypher-manual/3.5/csv/artists-with-headers.csv' AS line
CREATE (:Artist { name: line[0], year: toInteger(line[1])})
但是如果有列名,则不能这样使用,必须通过列名索引。即修改为下面两种用法:
LOAD CSV WITH HEADERS FROM 'https://neo4j.com/docs/cypher-manual/3.5/csv/artists-with-headers.csv' AS line
CREATE (:Artist { name: line.Name, year: toInteger(line.Year)})
LOAD CSV WITH HEADERS FROM 'https://neo4j.com/docs/cypher-manual/3.5/csv/artists-with-headers.csv' AS line
CREATE (:Artist { name: line['Name'], year: toInteger(line['Year'])})