8.6. Operators

Mathematical operators

The mathematical operators are +, -, *, / and %, ^.

Comparison operators

The comparison operators are =, <>, <, >, <=, >=, IS NULL, and IS NOT NULL. See the section called “Equality and Comparison of Values” on how they behave.

Boolean operators

The boolean operators are AND, OR, XOR, NOT.

String operators

Strings can be concatenated using the + operator.

Collection operators

Collections can be concatenated using the + operator. To check if an element exists in a collection, you can use the IN operator.

Property operators

[Note]Note

Since version 2.0, the previously existing property operators ? and ! have been removed. This syntax is no longer supported. Missing properties are now returned as NULL. Please use (NOT(has(<ident>.prop)) OR <ident>.prop=<value>) if you really need the old behavior of the ? operator. — Also, the use of ? for optional relationships has been removed in favor of the newly introduced OPTIONAL MATCH clause.

Equality and Comparison of Values

Equality

Cypher supports comparing values (see Section 8.1, “Values”) by equality using the = and <> operators.

Values of the same type are only equal if they are the same identical value (e.g. 3 = 3 and "x" <> "xy").

Maps are only equal if they map exactly the same keys to equal values and collections are only equal if they contain the same sequence of equal values (e.g. [3, 4] = [1+2, 8/2]).

Values of different types are considered as equal according to the following rules:

  • Paths are treated as collections of alternating nodes and relationships and are equal to all collections that contain that very same sequence of nodes and relationships.
  • Testing any value against NULL with both the = and the <> operators always is NULL. This includes NULL = NULL and NULL <> NULL. The only way to reliably test if a value v is NULL is by using the special v IS NULL, or v IS NOT NULL equality operators.

All other combinations of types of values cannot be compared with each other. Especially, nodes, relationships, and literal maps are incomparable with each other.

It is an error to compare values that cannot be compared.

Ordering and Comparison of Values

The comparison operators <= (for ascending) and >= (for descending) are used to compare values for ordering. The following points give some details on how the comparison is performed.

  • Numerical values are compared for ordering using numerical order (e.g. 3 < 4 is true).
  • String values are compared for ordering using lexicographic order (e.g. "x" < "xy").
  • Boolean values are compared for ordering such that false < true.
  • Comparing for ordering when one argument is NULL is NULL (e.g. NULL < 3 is NULL).
  • It is an error to compare other types of values with each other for ordering.

For other comparison operators, see the section called “Comparison operators”.