3.2.2. Naming rules and recommendations

We describe here rules and recommendations for the naming of node labels, relationship types, property names and variables.

3.2.2.1. Naming rules

  • Must begin with an alphabetic letter.

    • This includes "non-English" characters, such as å, ä, ö, ü etc.
    • If a leading non-alphabetic character is required, use backticks for escaping; e.g. `^n`.
  • Can contain numbers, but not as the first character.

    • To illustrate, 1first is not allowed, whereas first1 is allowed.
    • If a leading numeric character is required, use backticks for escaping; e.g. `1first`.
  • Cannot contain symbols.

    • An exception to this rule is using underscore, as given by my_variable.
    • An ostensible exception to this rule is using $ as the first character to denote a parameter, as given by $myParam.
    • If a leading symbolic character is required, use backticks for escaping; e.g. `$$n`.
  • Can be very long, up to 65535 (2^16 - 1) or 65534 characters, depending on the version of Neo4j.
  • Are case-sensitive.

    • Thus, :PERSON, :Person and :person are three different labels, and n and N are two different variables.
  • Whitespace characters:

    • Leading and trailing whitespace characters will be removed automatically. For example, MATCH ( a ) RETURN a is equivalent to MATCH (a) RETURN a.
    • If spaces are required within a name, use backticks for escaping; e.g. `my variable has spaces`.

3.2.2.2. Scoping and namespace rules

  • 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).

3.2.2.3. Recommendations

Here are the naming conventions we recommend using:

Node labels

Camel case, beginning with an upper-case character

:VehicleOwner rather than :vehice_owner etc.

Relationship types

Upper case, using underscore to separate words

:OWNS_VEHICLE rather than :ownsVehicle etc