0

i am using the Neo4j database on my mac (mac OS High Sierra) and would like to import a csv file into the database.

I wanna use the "Load CSV" command and my question is how to structure the command?

The structure of the csv-file is as following:

Header-Line:

SALES_VOLUMES,NET_SALES,CM1,PRODUCT_MAIN_GROUP,REGION,SBU,SALES_TYPE,DATA_SOURCE,PERIOD,PERIOD_YEAR,PERIOD_HALF_YEAR,PERIOD_QUARTER,PERIOD_MONTH,CURRENCY,USERID,ENTRY_TS

Attributes: line 2

267,484,116,Oettinger Mix Bier und Cola,South America,Oettinger,3rd_party,BW B,201003,2010,1,1,3,eur,system,27-NOV-10 08.43.59.000000000 PM

Attributes: line 3

0,0,0,Oettinger Schwarzbier,Asia,Oettinger,3rd_party,BW B,201003,2010,1,1,3,eur,system,27-NOV-10 08.44.00.000000000 PM

David
  • 41
  • 5
  • OK, but what have you tryed so far ? Have you taken a look at https://neo4j.com/docs/developer-manual/3.3/get-started/cypher/importing-csv-files-with-cypher/ ? – logisima May 09 '18 at 07:10
  • So what you have tried ? What was the error ? ... – logisima May 09 '18 at 11:18
  • Yeah, I did. I already tried to execute a Load CSV- command: LOAD CSV WITH HEADERS FROM 'file///Users/davidoff/Desktop/test.csv' AS line CREATE (:Artist { name: line.Name, year: toInteger(line.Year)}) (via http://localhost:7474/browser/) and i get the following error "Neo.ClientError.Statement.ExternalResourceFailed" with the message "Invalid URL". It seems more like a security problem that Neo4J doesnt want to accept local data. – David May 09 '18 at 11:24
  • 1
    Put the file into the `data` folder of Neo4j and then use this url `file:///test.csv` – logisima May 09 '18 at 11:28
  • Now it worked without an error. Thanks @logisima Somenow, now the nodes appear in the visualization, but the content doesnt. I guess, it´s just a syntax problem or a problem of the table structure.. – David May 09 '18 at 11:51
  • Do you also have an idea how i can manage to import attributes with decimals (e.g. 9,82) from the csv-fle into the database? @logisima I tried to use ":" as a fieldterminator for the headers in the csv-file, but then the database somehow doesnt accept the toInteger-function anymore. If I put the data in " "-signs, they dont appear at all in the database. – David May 17 '18 at 13:51
  • This is not due to the field delimitor, but to your decimal format. You should replace the `,` by a dot. : `toInteger('9,82')` but `toInteger('9.82')` is OK. Moreover, do you should use the toFloat instead ? – logisima May 17 '18 at 14:37
  • You were right. I replaced all the "," with a "." I used the toFloat-function and all the csv-files were imported correctly into the database. – David May 18 '18 at 12:52
  • Would you also agree that it is "best practice" to generate own IDs in the csv-file to work with data in Neo4J? @logisima Neo4Js own IDs are reused after a node is deleted in there and connects a newly created node with the deleted nodes ID with the references of the old node. – David May 18 '18 at 14:50

0 Answers0