Neo4j how to handle special characters like ” \ in Cypher statements
Solution 1
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.
Solution 2
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
![Admin](/assets/logo_square_200-5d0d61d6853298bd2a4fe063103715b4daf2819fc21225efa21dfb93e61952ea.png)
Admin
Updated on June 12, 2022Comments
-
Admin about 2 years
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 :)
-
Nigel Small about 9 yearsAlso, don't forget triple-single quotes
'''a 'quoted' word'''
and triple-double quotes"""another "quoted" word"""
. -
F Lekschas almost 9 years@NigelSmall How do you get triple quotes to work? I am getting a
Neo.ClientError.Statement.InvalidSyntax
error when I try to execute something likeMATCH (n:Test {id:'test'}) SET n.label = '''John Doe's house''';
-
Emadpres over 5 yearsI can't find it. Can you put a link please?
-
Dave Babbitt almost 2 years