Cypher Functions

String Functions

FunctionDescriptionExample
toLower(s)Convert to lowercasetoLower('Hello')'hello'
toUpper(s)Convert to uppercasetoUpper('Hello')'HELLO'
trim(s)Remove leading/trailing whitespacetrim(' hi ')'hi'
ltrim(s)Remove leading whitespaceltrim(' hi')'hi'
rtrim(s)Remove trailing whitespacertrim('hi ')'hi'
replace(s, from, to)Replace occurrencesreplace('hello', 'l', 'x')'hexxo'
substring(s, start, len)Extract substringsubstring('hello', 1, 3)'ell'
left(s, n)First n charactersleft('hello', 2)'he'
right(s, n)Last n charactersright('hello', 2)'lo'
split(s, delim)Split into listsplit('a,b,c', ',')['a','b','c']
reverse(s)Reverse stringreverse('hello')'olleh'
length(s)String lengthlength('hello')5
size(s)String length (alias)size('hello')5
toString(x)Convert to stringtoString(123)'123'

String Predicates

FunctionDescriptionExample
startsWith(s, prefix)Check prefixstartsWith('hello', 'he')true
endsWith(s, suffix)Check suffixendsWith('hello', 'lo')true
contains(s, sub)Check substringcontains('hello', 'ell')true

Math Functions

FunctionDescriptionExample
abs(n)Absolute valueabs(-5)5
ceil(n)Round upceil(2.3)3
floor(n)Round downfloor(2.7)2
round(n)Round to nearestround(2.5)3
sign(n)Sign (-1, 0, 1)sign(-5)-1
sqrt(n)Square rootsqrt(16)4
log(n)Natural logarithmlog(e())1
log10(n)Base-10 logarithmlog10(100)2
exp(n)e^nexp(1)2.718...
rand()Random 0-1rand()0.42...
random()Random 0-1 (alias)random()0.42...
pi()π constantpi()3.14159...
e()e constante()2.71828...

Trigonometric Functions

FunctionDescription
sin(n)Sine
cos(n)Cosine
tan(n)Tangent
asin(n)Arc sine
acos(n)Arc cosine
atan(n)Arc tangent

List Functions

FunctionDescriptionExample
head(list)First elementhead([1,2,3])1
tail(list)All but firsttail([1,2,3])[2,3]
last(list)Last elementlast([1,2,3])3
size(list)Lengthsize([1,2,3])3
range(start, end)Create rangerange(1, 5)[1,2,3,4,5]
reverse(list)Reverse listreverse([1,2,3])[3,2,1]
keys(map)Get map keyskeys({a:1, b:2})['a','b']

Aggregate Functions

FunctionDescriptionExample
count(x)Count itemscount(n), count(*)
sum(x)Sum valuessum(n.amount)
avg(x)Averageavg(n.score)
min(x)Minimummin(n.age)
max(x)Maximummax(n.age)
collect(x)Collect into listcollect(n.name)

Entity Functions

FunctionDescriptionExample
id(node)Get node/edge IDid(n)
labels(node)Get node labelslabels(n)['Person']
type(rel)Get relationship typetype(r)'KNOWS'
properties(x)Get all propertiesproperties(n)
startNode(rel)Start node of relationshipstartNode(r)
endNode(rel)End node of relationshipendNode(r)

Path Functions

FunctionDescriptionExample
nodes(path)Get all nodes in pathnodes(p)
relationships(path)Get all relationshipsrelationships(p)
rels(path)Get all relationships (alias)rels(p)
length(path)Path length (edges)length(p)

Type Conversion

FunctionDescriptionExample
toInteger(x)Convert to integertoInteger('42')42
toFloat(x)Convert to floattoFloat('3.14')3.14
toBoolean(x)Convert to booleantoBoolean('true')true
coalesce(x, y, ...)First non-null valuecoalesce(n.name, 'Unknown')

Temporal Functions

FunctionDescriptionExample
date()Current datedate()'2025-01-15'
datetime()Current datetimedatetime()
time()Current timetime()
timestamp()Unix timestamp (ms)timestamp()
localdatetime()Local datetimelocaldatetime()
randomUUID()Generate random UUIDrandomUUID()'550e8400-e29b-...'

Predicate Functions

FunctionDescriptionExample
exists(pattern)Pattern existsEXISTS { (n)-[:KNOWS]->() }
exists(prop)Property existsexists(n.email)
all(x IN list WHERE pred)All matchall(x IN [1,2,3] WHERE x > 0)
any(x IN list WHERE pred)Any matchany(x IN [1,2,3] WHERE x > 2)
none(x IN list WHERE pred)None matchnone(x IN [1,2,3] WHERE x < 0)
single(x IN list WHERE pred)Exactly onesingle(x IN [1,2,3] WHERE x = 2)

Reduce

FunctionDescriptionExample
reduce(acc = init, x IN list | expr)Fold/reducereduce(s = 0, x IN [1,2,3] | s + x)6

CASE Expressions

Searched CASE

Evaluates conditions in order and returns the first matching result:

RETURN CASE
    WHEN n.age < 18 THEN 'minor'
    WHEN n.age < 65 THEN 'adult'
    ELSE 'senior'
END AS category

Simple CASE

Compares an expression against values:

RETURN CASE n.status
    WHEN 'A' THEN 'Active'
    WHEN 'I' THEN 'Inactive'
    WHEN 'P' THEN 'Pending'
    ELSE 'Unknown'
END AS status_name

Comprehensions

List Comprehension

Create lists by transforming or filtering:

// Transform each element
RETURN [x IN range(1, 5) | x * 2]
// → [2, 4, 6, 8, 10]

// Filter elements
RETURN [x IN range(1, 10) WHERE x % 2 = 0]
// → [2, 4, 6, 8, 10]

// Filter and transform
RETURN [x IN range(1, 10) WHERE x % 2 = 0 | x * x]
// → [4, 16, 36, 64, 100]

Pattern Comprehension

Extract data from pattern matches within an expression:

// Collect names of friends
MATCH (p:Person)
RETURN p.name, [(p)-[:KNOWS]->(friend) | friend.name] AS friends

// With filtering
RETURN [(p)-[:KNOWS]->(f:Person) WHERE f.age > 21 | f.name] AS adult_friends

Map Projection

Create maps by selecting properties from nodes:

// Select specific properties
MATCH (n:Person)
RETURN n {.name, .age}
// → {name: "Alice", age: 30}

// Include computed values
MATCH (n:Person)
RETURN n {.name, status: 'active', upperName: toUpper(n.name)}