Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
08-14-2019 02:00 AM
Hi all,
I would like to know where I am going wrong with this query,
//Import of senate armed staff
Load CSV with headers from 'file:///Senate%20Armed%20Services%20Staff.csv' as line
with line
FOREACH
(ignoreME IN CASE WHEN line.`Employer` IS NOT NULL THEN [1] ELSE [] END |
IN CASE WHEN line.Employer CONTAINS "Senator" MERGE (s:Senator{Name:line.`Employer`}) ELSE MERGE (a:Account{Name:line.`Employer`})
)
I am trying to create 2 node labels one based on if the cell contains senator otherwise create an account node.
Kind regards,
Sam.
Solved! Go to Solution.
08-14-2019 06:35 AM
what is the result/outcome?
As a first guess, and when using Neo4j 3.5.8 the cypher statement of
Load CSV with headers from 'file:///Senate%20Armed%20Services%20Staff.csv' as line
with line
FOREACH
(ignoreME IN CASE WHEN line.`Employer` IS NOT NULL THEN [1] ELSE [] END |
IN CASE WHEN line.Employer CONTAINS "Senator" MERGE (s:Senator{Name:line.`Employer`}) ELSE MERGE (a:Account{Name:line.`Employer`})
)
;
fails with a syntax error and reports
Invalid input 'I': expected whitespace, comment, FROM GRAPH, CONSTRUCT, LOAD CSV, START, MATCH, UNWIND, MERGE, CREATE UNIQUE, CREATE, SET, DELETE, REMOVE, FOREACH, WITH, CALL or RETURN (line 6, column 1 (offset: 149))
"IN CASE WHEN line.Employer CONTAINS "Senator" MERGE (s:Senator{Name:line.`Employer`}) ELSE MERGE (a:Account{Name:line.`Employer`})"
are you ecnountering the same error or something entirely different? Are you using Neo4j 3.5.8?
If the same error then appropriate Cypher would be
Load CSV with headers from 'file:///Senate%20Armed%20Services%20Staff.csv' as line
with line
FOREACH
( ignoreME IN CASE WHEN line.Employer IS NOT NULL and line.Employer contains 'Senator' THEN [1] ELSE [] END |
MERGE (s:Senator {Name:line.Employer})
)
FOREACH
( ignoreME IN CASE WHEN line.Employer IS NOT NULL and NOT line.Employer contains 'Senator' THEN [1] ELSE [] END |
MERGE (a:Account{Name:line.`Employer`})
)
;
08-14-2019 06:35 AM
what is the result/outcome?
As a first guess, and when using Neo4j 3.5.8 the cypher statement of
Load CSV with headers from 'file:///Senate%20Armed%20Services%20Staff.csv' as line
with line
FOREACH
(ignoreME IN CASE WHEN line.`Employer` IS NOT NULL THEN [1] ELSE [] END |
IN CASE WHEN line.Employer CONTAINS "Senator" MERGE (s:Senator{Name:line.`Employer`}) ELSE MERGE (a:Account{Name:line.`Employer`})
)
;
fails with a syntax error and reports
Invalid input 'I': expected whitespace, comment, FROM GRAPH, CONSTRUCT, LOAD CSV, START, MATCH, UNWIND, MERGE, CREATE UNIQUE, CREATE, SET, DELETE, REMOVE, FOREACH, WITH, CALL or RETURN (line 6, column 1 (offset: 149))
"IN CASE WHEN line.Employer CONTAINS "Senator" MERGE (s:Senator{Name:line.`Employer`}) ELSE MERGE (a:Account{Name:line.`Employer`})"
are you ecnountering the same error or something entirely different? Are you using Neo4j 3.5.8?
If the same error then appropriate Cypher would be
Load CSV with headers from 'file:///Senate%20Armed%20Services%20Staff.csv' as line
with line
FOREACH
( ignoreME IN CASE WHEN line.Employer IS NOT NULL and line.Employer contains 'Senator' THEN [1] ELSE [] END |
MERGE (s:Senator {Name:line.Employer})
)
FOREACH
( ignoreME IN CASE WHEN line.Employer IS NOT NULL and NOT line.Employer contains 'Senator' THEN [1] ELSE [] END |
MERGE (a:Account{Name:line.`Employer`})
)
;
08-14-2019 06:49 AM
that worked, thanks for your help
All the sessions of the conference are now available online