PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, August 28, 2022

[FIXED] Why neo4j is not adding a new line with \n character coming in data from csv?

 August 28, 2022     csv, cypher, neo4j     No comments   

Issue

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'

Solution

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."
  }
}


Answered By - jose_bacoy
Answer Checked By - Senaida (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing