Expressions overview
This page contains an overview of the allowed expressions in Cypher®.
General
-
A variable:
n
,x
,rel
,myFancyVariable
,`A name with special characters in it[]!`
. -
A property:
n.prop
,x.prop
,rel.thisProperty
,myFancyVariable.`(special property name)`
. For more information, see Values and types → property types. -
A dynamic property:
n["prop"]
,rel[n.city + n.zip]
,map[coll[0]]
. For more information, seeWHERE
→ filter on dynamically computed properties. -
A parameter:
$param
,$0
. -
A list of expressions:
['a', 'b']
,[1, 2, 3]
,['a', 2, n.property, $param]
,[]
. -
A function call:
length(p)
,nodes(p)
. -
An aggregating function call:
avg(x.prop)
,count(*)
. -
A path-pattern:
(a)-[r]->(b)
,(a)-[r]-(b)
,(a)--(b)
,(a)-->()<--(b)
. -
An operator application:
1 + 2
,3 < 4
. -
A subquery expression:
COUNT {}
,COLLECT {}
,EXISTS {}
,CALL {}
. -
A regular expression:
a.name =~ 'Tim.*'
. -
null
.
Expressions containing unsanitized user input may make your application vulnerable to Cypher injection. Consider using parameters instead. Learn more in Protecting against Cypher Injection. |
Most expressions in Cypher evaluate to |
Numerical
-
A numeric (
INTEGER
orFLOAT
) literal:13
,-40000
,3.14
. -
A numeric (
INTEGER
orFLOAT
) literal in scientific notation:6.022E23
. -
A hexadecimal
INTEGER
literal (starting with0x
):0x13af
,0xFC3A9
,-0x66eff
. -
An octal
INTEGER
literal (starting with0o
):0o1372
,-0o5671
. -
A
FLOAT
literal:Inf
,Infinity
,NaN
. -
null
.
Any numeric literal may contain an underscore |
String
-
A
STRING
literal:'Hello'
,"World"
. -
A case-sensitive
STRING
matching expression:a.surname STARTS WITH 'Sven'
,a.surname ENDS WITH 'son'
ora.surname CONTAINS 'son'
. -
null
.
Boolean
-
A
BOOLEAN
literal:true
,false
. -
A predicate expression (i.e. an expression returning a
BOOLEAN
value):a.prop = 'Hello'
,length(p) > 10
,a.name IS NOT NULL
. -
Label and relationship type expressions:
(n:A|B)
,()-[r:R1|R2]->()
. -
null
.
Graph references
-
Database and alias names when managing databases and aliases:
CREATE DATABASE <symbolic-name>
. -
Static graph references:
USE <symbolic-name>
orUSE <symbolic-name>.<symbolic-name>
(for constituents of a composite databases). -
Dynamic graph reference with the
graph.byName
function, to access a graph of a given name:USE graph.byName(<string-expression>)
. -
Dynamic graph references with the
graph.byElementId
function, to access a graph of a given node or relationship:USE graph.byName(<element-id-string>)
. -
Retrieving properties of a graph with the
graph.propertiesByName
function:graph.propertiesByName(<string-expression>)
.
Rules on string expressions for graph references when using identifiers (static graph references, administration commands) or a string (graph.byName function):
-
Unquoted dots are separators between a composite database and its constituent. For example,
composite.db1
represents the constituentcomposite.db1
in the composite databasecomposite
. To refer to a database with a dot (.
) in its name, quote the graph reference instead:`composite.db1`
. -
When resolving a graph reference within a graph function, the string argument is parsed like a static graph reference. Thus,
USE graph.byName(<graph-reference>)
is typically equivalent toUSE <graph-reference>
. However, escaping rules for symbolic names are applied to the argument. For string literals, both the escaping rules for string literals (during query parsing) and symbolic names (during graph reference evaluation) are applied. For example, the graph reference inUSE graph.byName('composite.1\\u0041')
resolves to the constituentcomposite.1a
of the composite databasecomposite
.