Boolean, numeric, and string literals

This page describes the literal forms of numerical (INTEGER and FLOAT), STRING, and BOOLEAN values in expressions.

Expressions containing unsanitized user input may make your application vulnerable to Cypher® injection. Consider using parameters instead. For more information, see Neo4j Knowledge Base → Protecting against Cypher Injection.

Boolean

Boolean literals represent BOOLEAN values. A boolean literal may be written as:

  • The literal true

  • The literal false

Numerical

Numerical literals can represent INTEGER or FLOAT values. A numerical literal may be written as:

  • A decimal INTEGER literal: 13, -40000

  • A hexadecimal INTEGER literal (prefix 0x): 0x13af, 0xFC3A9, -0x66eff

  • An octal INTEGER literal (prefix 0o): 0o1372, -0o5671

  • A FLOAT literal in common notation: 3.14

  • A FLOAT literal in scientific notation: 6.022E23, 1e-9

  • Literals for special FLOAT values: Inf, Infinity, NaN

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. For example: 1_000_000, 0x_FC3A9, and 0o_1372.

String

String literals represent STRING values. They are written using single(') or double quotes (") and may contain escape sequences using a backslash (\). A string literal may be written as:

  • A STRING quoted with single quotes: 'Hello, 42'

  • A STRING quoted with double quotes: "Hello, 42"

  • A STRING with whitespace: ' hello '

  • A STRING with escape sequences: 'Line 1\nLine 2', 'Tab\tseparated'

  • A STRING containing Unicode characters: '그래프는 어디에나 있다'

  • A STRING using a Unicode code point: 'Name: \u004Aohn' (produces 'Name: John')

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)

String interpolation

String interpolation lets one or more expressions be embedded directly inside a string literal. Each embedded expression is evaluated and inserted into the resulting STRING, so the string does not need to be built up manually with the string concatenation operators.

An interpolated string is written by prefixing a quoted string with s or S, and wrapping each expression to be evaluated in curly braces ({ and }):

  • s"Hello, {p.name}"

  • S’Hello, {p.name}'

Interpolated strings can be quoted with either single or double quotes, following the same quoting rules as string literals, and may contain any number of {expression} placeholders.

Every embedded expression is automatically converted to a STRING using toString(). Because toString() does not support them, expressions that evaluate to MAP, LIST, NODE, PATH, or RELATIONSHIP values cannot be used inside an interpolated expression.

To include a literal curly brace in an interpolated string, escape it with a backslash: \{ or \}.

Take care when using string interpolation to build Cypher strings that get passed into plugin procedures which execute dynamic Cypher, such as apoc.cypher.run(). Interpolating unsanitized values into such strings increases the risk of Cypher injection. Where possible, use parameters instead.

Examples

Interpolating a node property
CREATE (p:Person {name: 'Alice'})
RETURN s"Hello, {p.name}!" AS greeting
Result
greeting

"Hello, Alice!"

Rows: 1

Multiple placeholders in a single interpolated string
WITH 'Keanu' AS firstName, 'Reeves' AS lastName
RETURN s"{firstName} {lastName}" AS fullName
Result
fullName

"Keanu Reeves"

Rows: 1

Non-STRING values are automatically converted using toString().

Interpolating a non-STRING value
WITH 42 AS age
RETURN s"Age: {age}" AS result
Result
result

"Age: 42"

Rows: 1

Escaping literal curly braces
RETURN s"Use \{curly\} braces" AS result
Result
result

"Use {curly} braces"

Rows: 1

Interpolated strings can be nested, since an embedded expression may itself be an interpolated string.

Nested string interpolation
WITH 'World' AS name
RETURN s"Outer: {s'Inner, {name}!'}" AS result
Result
result

"Outer: Inner, World!"

Rows: 1