Neo4j how to handle special characters like ” \ in Cypher statements

后端 未结 2 1702
-上瘾入骨i
-上瘾入骨i 2020-12-21 05:15

I am using py2neo to load JSON data into Neo4j as chyper statements. My problem is that sometimes there are signs as “ ‘ \\ etc in the strings I want to impor

相关标签:
2条回答
  • 2020-12-21 05:42

    I would suggest to use parameters, then the cypher parser doesn't see them.

    And it's just an name -> string you pass via a dictionary to the execute method.

    0 讨论(0)
  • 2020-12-21 05:45

    If you want to include double quotes, you can wrap in single quotes:

    CREATE (n:Node {name:'hello " world'}) 
    RETURN n.name
    
    n.name
    hello " world
    

    If you want to include single quotes, you can wrap in double quotes:

    CREATE (n:Node {name:"hello ' world"}) 
    RETURN n.name
    
    n.name
    hello ' world
    

    If it's more complicated than that, you can escape the character:

    CREATE (n:Node {name:"hello \" world"}) 
    RETURN n.name
    
    n.name
    hello " world
    

    You can also include backslashes by escaping them:

    CREATE (n:Node {name:"hello \\ world"}) 
    RETURN n.name
    
    n.name
    hello \ world
    
    0 讨论(0)
提交回复
热议问题