8.2. Expressions

Expressions in general

An expression in Cypher can be:

  • A decimal (integer or double) literal: 13, -40000, 3.14, 6.022E23.
  • A hexadecimal integer literal (starting with 0x): 0x13zf, 0xFC3A9, -0x66eff.
  • An octal integer literal (starting with 0): 01372, 01278, -05671.
  • A string literal: "Hello", 'World'.
  • A boolean literal: true, false, TRUE, FALSE.
  • An identifier: n, x, rel, myFancyIdentifier, `A name with weird stuff in it[]!`.
  • A property: n.prop, x.prop, rel.thisProperty, myFancyIdentifier.`(weird property name)`.
  • A parameter: {param}, {0}
  • A collection of expressions: ["a", "b"], [1,2,3], ["a", 2, n.property, {param}], [ ].
  • A function call: length(p), nodes(p).
  • An aggregate function: avg(x.prop), count(*).
  • A path-pattern: (a)-->()<--(b).
  • An operator application: 1 + 2 and 3 < 4.
  • A predicate expression is an expression that returns true or false: a.prop = "Hello", length(p) > 10, has(a.name).
  • A CASE expression.

Note on string literals

String literals can contain these escape sequences.

Escape sequenceCharacter

\t

Tab

\b

Backspace

\n

Newline

\r

Carriage return

\f

Form feed

\'

Single quote

\"

Double quote

\\

Backslash

Case Expressions

Cypher supports CASE expressions, which is a generic conditional expression, similar to if/else statements in other languages. Two variants of CASE exist — the simple form and the generic form.