cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Double Quote issue in the Load CSV

Kailash
Graph Buddy

Hi All,

Good Evening, I am not sure if this is a bug in Load CSV or is there anyway to sort it out.

When I have a double quote in the Start of any field(§"TestUser1) then it expects a closing double quote in the end, but when i have it in the middle of field then it works fine(§Test "User1) . For some reason i have a double quote in the start of the field but there is no ending double quote. file size is huge, so I can not manually remove it.

Sample Data for testing purpose only, my csv looks like below where Line 1 has the record having double quote(") in start. Please ignore the delimiter used here.

Actually speaking when my delimiter is § then it should pick the whole and work.

§SNO§EmailId§FirstName§EmailId§LastName§HiringDate§;
§1§10001§Test1§abc@test1.com§"TestUser1§2019-02-05§;
§2§10002§Test2§abc@test2.com§TestUser2§2019-02-05§;
§3§10003§Test3§abc@test3.com§TestUser3§2019-02-05§;

`LOAD CSV WITH HEADERS FROM "file:///test1.csv" AS eachLine FIELDTERMINATOR '§' WITH eachLine  return eachLine limit 10`

Error Message:
Neo.DatabaseError.General.UnknownError: At /home/mytestapp/neo4j-enterprise-3.5.3/import/test1.csv @ position 211 - Missing end for quote (") which started on line 1

The above code works fine if the input is §"TestUser1"§ or §Test"User1§.

Any help will be appreciated.
1 REPLY 1

ameyasoft
Graph Maven
There are couple of ways:

1. Open your .csv file in Nogtepad++ or any other text editor and use find/replace to replace " with blank. Save this file and use.

2. This will involve a few changes to your import process:

Here are the steps:

Step 1: Remove the header line in your .csv file

Step 2:  Leave the delimiter to default (,)

Step 3: Use LOAD CSV FROM "file..." (do not use FIELDTERMINATOR)

I created a .csv file with your sample data for this test. 

LOAD CSV FROM 'file:///utext1a.csv' AS row
unwind row as r1
with split(replace(r1, '"', ''), '§') as s1
return s1[0] as Col1, s1[1] as Col2, s1[2] as Col3, s1[4] as Col4, s1[5] as Col5

Result:
Col1   Col2	Col3	        Col4.        	Col5
"1"	"10001"	"Test1"	"TestUser1"	"2019-02-05"
"1"	"10001"	"Test1"	"TestUser1"	"2019-02-05"
"2"	"10002"	"Test2"	"TestUser2"	"2019-02-05"
"3"	"10003"	"Test3"	"TestUser3"	"2019-02-05"


Use the split items like s1[0] to s1[5] as properties for each node that you create.

Like merge (c:Test {val: s1[0]})

Hope this works for you.