Naming rules and recommendations
This page describes rules and recommendations for the naming of node labels, relationship types, property names, variables, indexes, and constraints.
Naming rules
-
Alphabetic characters:
-
Names should begin with an alphabetic character.
-
This includes "non-English" characters, such as
å
,ä
,ö
,ü
etc.
-
-
Numbers:
-
Names should not begin with a number.
-
To illustrate,
1first
is not allowed, whereasfirst1
is allowed.
-
-
Symbols:
-
Names should not contain symbols, except for underscore, as in
my_variable
, or$
as the first character to denote a parameter, as given by$myParam
.
-
-
Length:
-
Can be very long, up to
65535
(2^16 - 1
) or65534
characters, depending on the version of Neo4j.
-
-
Case-sensitive:
-
Names are case-sensitive and thus,
:PERSON
,:Person
and:person
are three different labels, andn
andN
are two different variables.
-
-
Whitespace characters:
-
Leading and trailing whitespace characters will be removed automatically. For example,
MATCH ( a ) RETURN a
is equivalent toMATCH (a) RETURN a
.
-
Using special characters in names
Non-alphabetic characters, including numbers, symbols and whitespace characters, can be used in names, but must be quoted using backticks.
For example: `^n`
, `1first`
, `$$n`
, and `my variable has spaces`
.
Database names are an exception and may include dots without the need for quoting using backticks, although this behavior is deprecated as it may introduce ambiguity when addressing composite databases.
For example: naming a database foo.bar.baz
is valid, but deprecated. `foo.bar.baz`
is valid.
Within a name quoted by backticks, the following character representations are allowed:
Character representation | Description |
---|---|
|
Backtick |
|
Unicode UTF-16 code point (4 hex digits must follow the |
Using names quoted in backticks with unsanitized user input makes you vulnerable to Cypher® injection. Some techniques to mitigate this are:
|
Several special characters have been deprecated and will require escaping in the next major release of Neo4j. For the comprehensive list of deprecated characters, see the deprecations page. |
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)
.
-
Recommendations
Here are the recommended naming conventions:
Node labels |
Camel-case, beginning with an upper-case character |
|
Relationship types |
Upper-case, using underscore to separate words |
|
Length limit of identifiers
Neo4j’s block format implements GQL’s limit on the maximum length of identifiers.
The maximum limit is set to 16,383 characters in an identifier. This means that node labels, relationship types, and property keys cannot include more than 16,383 characters.