Expressions overview

This page contains an overview of the allowed expressions in Cypher®.

General

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 null if any of their inner expressions are null. Notable exceptions are the operators IS NULL, IS NOT NULL, and the type predicate expressions.

Numerical

  • A numeric (INTEGER or FLOAT) literal: 13, -40000, 3.14.

  • A numeric (INTEGER or FLOAT) literal in scientific notation: 6.022E23.

  • A hexadecimal INTEGER literal (starting with 0x): 0x13af, 0xFC3A9, -0x66eff.

  • An octal INTEGER literal (starting with 0o): 0o1372, -0o5671.

  • A FLOAT literal: Inf, Infinity, NaN.

  • null.

Any numeric literal may contain an underscore _ between digits. There may be an underscore between the 0x or 0o and the digits for hexadecimal and octal literals.

String

  • A STRING literal: 'Hello', "World".

  • A case-sensitive STRING matching expression: a.surname STARTS WITH 'Sven', a.surname ENDS WITH 'son' or a.surname CONTAINS 'son'.

  • null.

String literal escape sequences

String literals can contain the following escape sequences:

Escape sequence Character

\t

Tab

\b

Backspace

\n

Newline

\r

Carriage return

\f

Form feed

\'

Single quote

\"

Double quote

\\

Backslash

\uxxxx

Unicode UTF-16 code point (4 hex digits must follow the \u)

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> or USE <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 constituent composite.db1 in the composite database composite. 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 to USE <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 in USE graph.byName('composite.1\\u0041') resolves to the constituent composite.1a of the composite database composite.