Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 :)

like image 734
Jon Avatar asked May 28 '15 17:05

Jon


People also ask

How do you escape special characters in database user and role names Neo4j?

Non-alphabetic characters, including numbers, symbols and whitespace characters, can be used in names, but must be escaped using backticks. For example: `^n` , `1first` , `$$n` , and `my variable has spaces` .

Is Neo4j case sensitive?

Neo4j database is case sensitive. By default, property values are matched by Bloom in a case sensitive fashion, if they begin with any of the matching tokens input by the user. If you would like search suggestions to be case insensitive, you can enable Case insensitive search and suggestions under Bloom settings.

WHAT IS WITH clause in Cypher?

The WITH clause allows query parts to be chained together, piping the results from one to be used as starting points or criteria in the next. It is important to note that WITH affects variables in scope.

Can relationships have properties in Neo4j?

Relationships always has a direction (one direction). Relationships must have a type (one type) to define (classify) what type of relationship they are. Nodes and relationships can have properties (key-value pairs), which further describe them.


1 Answers

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
like image 125
Nicole White Avatar answered Sep 19 '22 11:09

Nicole White