Loading CSV file with multiple words in column names


(Puneet Madhavan) #1

Hi,

I am trying to read my CSV file which has spaces in column name: Column A = 'Source Variable'
When I am trying to read this, it gives me an error:

Neo.ClientError.Statement.SyntaxError: Invalid input 'V': expected whitespace, comment, '(', '.', node labels, '[', "=~", IN, STARTS, ENDS, CONTAINS, IS, '^', '*', '/', '%', '+', '-', '=', "<>", "!=", '<', '>', "<=", ">=", AND, XOR, OR, LOAD CSV, FROM, INTO, START, MATCH, UNWIND, MERGE, CREATE GRAPH >>, CREATE >> GRAPH, CREATE GRAPH, CREATE, SET, DELETE GRAPHS, DELETE, REMOVE, FOREACH, WITH, CALL, PERSIST, RELOCATE, RETURN, SNAPSHOT, UNION, ';' or end of input (line 4, column 23 (offset: 99)) "WHERE NOT line.Source Variable IS NULL and NOT line.SourceFile is NULL" ^

My code:

LOAD CSV WITH HEADERS FROM "file:///Matrix.csv" AS line WITH line

WITH line
WHERE NOT line.Source Variable IS NULL and NOT line.SourceFile is NULL
MERGE (a: Studytest {name: line.Studytest, type: 'Study'})
//CREATE (domain: Domain {name: line.Domain})
mergE (b: Domaintest {name: line.Domaintest, type: 'Domain', domain_identifier: line.Studytest + line.Domaintest})

Merge (c: SourceFile {name: line.SourceFile,type: 'Source_File', file_identifier: line.Studytest + line.Domaintest + line.SourceFile})

Merge (d: SourceVariable {name: line.Source Variable,type: 'Source_Variable', field_identifier: line.Studytest + line.Domaintest + line.SourceFile + line.Source Variable})

MERGE (d)-[z:Part_of]->(c)

MERGE (c)-[q:Part_of]->(b)

MERGE (b)-[p:Part_of]->(a)

RETURN a;


(Stefan Armbruster) #2

you need to use back ticks for quoting, so

line.`Source Variable`

(Puneet Madhavan) #3

Hi,

I tried that. I got the below error:

Neo.ClientError.Statement.SyntaxError: Invalid input ''': expected an identifier, whitespace, a function name or a property key name (line 4, column 16 (offset: 92))
"WHERE NOT line.'Source Variable' IS NULL and NOT line.SourceFile is NULL"


(Andrew Bowman) #4

Your example is using single quote characters: '. This is not the same as backticks (on a US keyboard, shares the same key as the tilde ~ symbol, and is next to the 1 key): `


(Puneet Madhavan) #5

Thank you!

Its resolved now :slightly_smiling_face: