Neo4j | Naming rules and recommendations

There is few rules for naming, to naming of node labels, relationship types, property names and variables have to follow some rules unless error will occurred. Rules for Naming:

  • To name node labels, relation types, property names also variables names should start with the alphabetic letter. This could be non-English character also. If the numeric character is required to name anything mentioned above then you can use the backticks for escaping the non-alphabetic character like `^n`.
  • Naming can contains the number but not in first place like 1Beginner is not allowed. You can use that as Beginner1 or Geek1s. But if you have to put a numeric at the begin then similarly use the backticks like `1Beginner` that backticks will skip the 1 and others characters behave as it should be.
  • The naming in Neo4j can not contains any kind of special symbols for naming. But the underscore is allowed, if the special symbol is required then use the backticks.
  • Naming could be to long 65535 (2^16 – 1) or 65534 it basically depends on the version of Neo4j.
  • Naming in Neo4j is case sensitive like :Beginner, :Beginner and :Beginner are three different labels and g and G are different variables.
  • White-space characters are acceptable all the Leading and trailing white-space characters will be removed automatically. Like MATCH ( a ) RETURN a is equivalent to MATCH (a) RETURN a. If spaces are required within a name, use backticks for escaping like `my variable has spaces`.

Rules for Scoping and namespace:

  • All the Node labels, relationship types and property names may re-use names. The following query?—?with a for the label, type and property name?—?is valid:
CREATE (a:a {a: 'a'})-[r:a]?(b:a {a: 'a'}).
  • Variables for nodes and relationships must not re-use names within the same query scope. The following query is not valid as the node and relationship both have the name
a: CREATE (a)-[a]?(b)

Recommended for naming node labels, relationship types, property names and variables:

  • Node labels: Try to use the Camel case, beginning with an upper-case character like below example.
:w3wiki rather than :w3wiki
  • Relationship types: Try to use the Upper case, you can use the underscore to separate words
:Beginner_for_Beginner rather than :w3wiki 

Reference:https://neo4j.com/docs/cypher-manual/current/syntax/naming/


Contact Us