You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用LOAD CSV导入CSV至图数据库遇语法错误,请求排查

问题描述

尝试导入以下CSV文件至图数据库:

"metaphor","entailmentDescription","example","sourceFrame","targetFrame","isASourceSubcaseOf"
metaphor1,escription,example,sf,tf,sbsbs

执行的Cypher命令如下:

LOAD CSV FROM 'file:///Query(8).csv' AS row
WITH row[0] AS metaphor, row[1] AS entailmentDescription, row[2] AS example, row[3] AS sourceFrame, row[4] AS targetFrame
MERGE (p:Metaphor {metaphor: metaphor})
  SET p.entailmentDescription= entailmentDescription, p.example= example, p.sourceFrame= sourceFrame, p.targetFrame= targetFrame
RETURN count(p);

命令执行后触发语法错误:

Invalid input : expected ")", "WHERE", "{" or a parameter (line 3, column 19 (offset: 184))

错误排查与修复方案

核心原因:文件名特殊字符未转义

CSV文件名Query(8).csv中的括号属于Cypher的特殊语法字符,会被解析器误判为参数占位符,导致语法解析失败。

修复步骤

  1. 转义文件名中的括号
    修改LOAD CSV语句,用反斜杠转义括号:

    LOAD CSV FROM 'file:///Query\\(8\\).csv' AS row
    WITH row[0] AS metaphor, row[1] AS entailmentDescription, row[2] AS example, row[3] AS sourceFrame, row[4] AS targetFrame
    MERGE (p:Metaphor {metaphor: metaphor})
      SET p.entailmentDescription= entailmentDescription, p.example= example, p.sourceFrame= sourceFrame, p.targetFrame= targetFrame
    RETURN count(p);
    
  2. 替代方案:使用双引号包裹文件路径
    也可以用双引号替代单引号包裹文件路径,避免特殊字符解析问题:

    LOAD CSV FROM "file:///Query(8).csv" AS row
    WITH row[0] AS metaphor, row[1] AS entailmentDescription, row[2] AS example, row[3] AS sourceFrame, row[4] AS targetFrame
    MERGE (p:Metaphor {metaphor: metaphor})
      SET p.entailmentDescription= entailmentDescription, p.example= example, p.sourceFrame= sourceFrame, p.targetFrame= targetFrame
    RETURN count(p);
    

额外优化建议

你的CSV包含6列(最后一列isASourceSubcaseOf),如果需要导入该字段,可扩展语句如下:

LOAD CSV FROM "file:///Query(8).csv" AS row
WITH row[0] AS metaphor, row[1] AS entailmentDescription, row[2] AS example, row[3] AS sourceFrame, row[4] AS targetFrame, row[5] AS isASourceSubcaseOf
MERGE (p:Metaphor {metaphor: metaphor})
  SET p.entailmentDescription= entailmentDescription, p.example= example, p.sourceFrame= sourceFrame, p.targetFrame= targetFrame, p.isASourceSubcaseOf= isASourceSubcaseOf
RETURN count(p);

内容的提问来源于stack exchange,提问作者Idkwhatywantmed

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.01 18:53:23