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

寵の児 提交于 2019-11-28 10:24:13

问题


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 import as properties to Nodes:

MERGE (p:Node {name:’This sign ‘ gives error’})

If I change to:

MERGE (p:Node {name:” This sign ‘ gives error”})

It will work for the statement over but it will fail when a is in an input string.

Is there a way to say that all (or almost all) special character is allowed inside the string? Sorry if this is a stupid question :)


回答1:


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



回答2:


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.



来源:https://stackoverflow.com/questions/30513601/neo4j-how-to-handle-special-characters-like-in-cypher-statements

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