Neo4J ClientError.Statement.SyntaxError

混江龙づ霸主 提交于 2020-01-23 12:59:09

问题


I am getting Neo.ClientError.Statement.SyntaxError while loading data from CSV file.

Neo.ClientError.Statement.SyntaxError: Invalid input 'h': expected 'i/I' (line 5, column 3 (offset: 189)) "Merge (Zip_Code:Zip_Code {code: row.zip_cd,type:'location'})"

Here is my Query:

 Using Periodic Commit
LOAD CSV WITH HEADERS FROM "file:///DOL_data_whd_whisard_reduced.csv" AS row
Merge (State_Code:State_Code {code: row.st_cd})
    where not row.st_cd is null

Merge (Zip_Code:Zip_Code {code: row.zip_cd,type:'location'})
    where not row.zip_cd is null
Merge (Zip_Code)-[:located_in]->(State_Code)

There are some blank records in the csv and hence I have used not null but this is giving me error as:

Can anyone help me out of it?


回答1:


You are getting an error because you are using WHERE with MERGE clause. WHERE can not be used with MERGE.

You can modify your query to remove the syntax error as follows:

USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM "file:///DOL_data_whd_whisard_reduced.csv" AS row
WITH row
WHERE NOT row.st_cd IS NULL AND NOT row.zip_cd IS NULL
MERGE (state_code:State_Code {code: row.st_cd})
MERGE (zip_code:Zip_Code {code: row.zip_cd, type:'location'})
MERGE (zip_code)-[:located_in]->(state_code)

NOTE:

  1. This will skip the record if one of st_cd or zip_cd is NULL.
  2. It's not recommended to use more than one MERGE in a single query, consider writing 3 separate queries for this.

Recommended method:

Load State codes:

USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM "file:///DOL_data_whd_whisard_reduced.csv" AS row
WITH row
WHERE NOT row.st_cd IS NULL 
MERGE (state_code:State_Code {code: row.st_cd})

Load Zip codes:

USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM "file:///DOL_data_whd_whisard_reduced.csv" AS row
WITH row
WHERE NOT row.zip_cd IS NULL
MERGE (zip_code:Zip_Code {code: row.zip_cd, type:'location'})

Create State-Zip relationships:

USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM "file:///DOL_data_whd_whisard_reduced.csv" AS row
WITH row
WHERE NOT row.st_cd IS NULL AND NOT row.zip_cd IS NULL
MATCH (state_code:State_Code {code: row.st_cd})
MATCH (zip_code:Zip_Code {code: row.zip_cd, type:'location'})
MERGE (zip_code)-[:located_in]->(state_code)


来源:https://stackoverflow.com/questions/56593300/neo4j-clienterror-statement-syntaxerror

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!