Neo4J ClientError.Statement.SyntaxError
Neo4J ClientError.Statement.SyntaxError
我在从 CSV 文件加载数据时收到 Neo.ClientError.Statement.SyntaxError。
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'})"
这是我的查询:
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)
csv 中有一些空白记录,因此我使用了 not null 但这给了我错误:
谁能帮我解决这个问题?
您正在使用带有 MERGE
子句的 WHERE
时出现错误。 WHERE
不能与 MERGE
一起使用。
您可以修改查询以删除语法错误,如下所示:
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:
- This will skip the record if one of
st_cd
or zip_cd
is NULL.
- It's not recommended to use more than one
MERGE
in a single query, consider writing 3 separate queries for this.
推荐方法:
加载状态代码:
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})
加载邮政编码:
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'})
创建 State-Zip 关系:
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)
我在从 CSV 文件加载数据时收到 Neo.ClientError.Statement.SyntaxError。
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'})"
这是我的查询:
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)
csv 中有一些空白记录,因此我使用了 not null 但这给了我错误:
谁能帮我解决这个问题?
您正在使用带有 MERGE
子句的 WHERE
时出现错误。 WHERE
不能与 MERGE
一起使用。
您可以修改查询以删除语法错误,如下所示:
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:
- This will skip the record if one of
st_cd
orzip_cd
is NULL.- It's not recommended to use more than one
MERGE
in a single query, consider writing 3 separate queries for this.
推荐方法:
加载状态代码:
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})
加载邮政编码:
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'})
创建 State-Zip 关系:
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)