Home > Mobile >  Why neo4j is not adding a new line with \n character coming in data from csv?
Why neo4j is not adding a new line with \n character coming in data from csv?

Time:07-22

I am having some data coming from csv which has \n character in it and I expect neo4j to add a new line when assigning that string to some attribute in node. Apparently its not working. I can see \n character as it is added in the string.

How to make it work? Thanks in Advance.

Following is one such string example from CSV:

Combo 4 4 4 5 \n\nSpare Fiber Inventory. \nMultimode Individual fibers from 9927/9928 to FDB.\nNo available spares from either BTS to FDB - New conduits would be required\n\nFrom FDB to tower top. 9 of 9 Spares available on 2.5 riser cables.

My load command:

USING PERIODIC COMMIT 500
LOAD CSV WITH HEADERS 
FROM 'file:///abc.csv' AS line
WITH line WHERE line.parent <> "" AND line.type = 'LSD' AND line.parent_type = 'XYZ'

CodePudding user response:

This is a hack that I made to replace the occurrences of \n with a newline. The character \ is an escape character so it will replace \n with a new line in line 4. Do not remove line 5 and combine with line 4.

LOAD CSV WITH HEADERS 
FROM 'file:///abc.csv' AS line
WITH line WHERE line.parent <> ""
WITH replace(line.parent,'\\n',"   
") as parent
MERGE (p:Parent {parent: parent}) 

RESULT:

{
  "identity": 16,
  "labels": [
    "Parent"
  ],
  "properties": {
"parent": "Combo 4 4 4 5    
   
Spare Fiber Inventory.    
Multimode Individual fibers from 9927/9928 to FDB.   
No available spares from either BTS to FDB - New conduits would be required   
   
From FDB to tower top. 9 of 9 Spares available on 2.5 riser cables."
  }
}
  • Related