-1

I have an integer-value that I want to be saved as a string-value in Neo4j using Cypher.

LOAD CSV WITH HEADERS FROM 'file:///nodes-addresses.csv' AS line 
CREATE (:Address line[0], address: line[1], name: line[2], countries: line[3], countries_codes: line[4], sourceID: line[5], valid_until: line[6], note: line[7]})

I've looked through the Cypher manual and found toString but this is still throwing an error.

Neo.ClientError.Statement.SyntaxError

Type mismatch: map key must be given as String, but was Integer (line 2, column 42 (offset: 108))
"CREATE (:Address {node_id: toString(line[0]), address: line[1], name: line[2], countries: line[3], countries_codes: line[4], sourceID: line[5], valid_until: line[6], note: line[7]})"

I've adding a character in and outside of the toString and other examples or commands.
toString('x'+line[0]), 'x'+toString(line[0]), toStr(line[0])
But none have worked.

How am I supposed to convert a integer to a string on import?

ZM.TSS
  • 31
  • 3

1 Answers1

1

When you specify WITH HEADERS in your LOAD CSV clause, the first line of your CSV file is treated as a header, and every data row returned is a map instead of an array.

So, if your data file's header row looks like this:

node_id,address,name,countries,countries_codes,sourceID,valid_until,note

then your code should look like this (assuming every property value is supposed to be a string):

LOAD CSV WITH HEADERS FROM 'file:///nodes-addresses.csv' AS r 
CREATE (:Address {
  address: r.address, name: r.name, countries: r.countries,
  countries_codes: r.countries_codes, sourceID: r.sourceID,
  valid_until: r.valid_until, note: r.note
})

or, since in this example the header names and the node property names exactly match, you can just use do this:

LOAD CSV WITH HEADERS FROM 'file:///nodes-addresses.csv' AS r
CREATE (a:Address)
SET a = r
cybersam
  • 63,203
  • 6
  • 53
  • 76