Cypher Functions

Every function available in GraphQLite Cypher queries, organized by category.


String Functions

SignatureReturnsDescription
toUpper(s)StringConvert to uppercase
toLower(s)StringConvert to lowercase
trim(s)StringRemove leading and trailing whitespace
ltrim(s)StringRemove leading whitespace
rtrim(s)StringRemove trailing whitespace
btrim(s)StringRemove leading and trailing whitespace (alias of trim)
substring(s, start)StringSubstring from start (0-based) to end
substring(s, start, len)StringSubstring of length len from start
replace(s, search, replacement)StringReplace all occurrences of search with replacement
reverse(s)StringReverse characters
left(s, n)StringFirst n characters
right(s, n)StringLast n characters
split(s, delimiter)List<String>Split string into list of substrings
toString(val)StringConvert any value to its string representation
size(s)IntegerNumber of characters in string
isEmpty(s)Booleantrue if string has length zero or is null
char_length(s)IntegerNumber of characters (alias of size)
character_length(s)IntegerNumber of characters (alias of size)

Examples

RETURN toUpper('hello')           -- 'HELLO'
RETURN substring('abcdef', 2, 3)  -- 'cde'
RETURN split('a,b,c', ',')        -- ['a', 'b', 'c']
RETURN left('abcdef', 3)          -- 'abc'

Math Functions

SignatureReturnsDescription
abs(n)NumberAbsolute value
ceil(n)IntegerCeiling (smallest integer >= n)
floor(n)IntegerFloor (largest integer <= n)
round(n)IntegerRound to nearest integer
round(n, precision)FloatRound to precision decimal places
sqrt(n)FloatSquare root
sign(n)Integer-1, 0, or 1
log(n)FloatNatural logarithm
log10(n)FloatBase-10 logarithm
exp(n)Floate raised to the power n
e()FloatEuler's number (2.718…)
pi()FloatPi (3.141…)
rand()FloatRandom float in [0, 1)
toInteger(val)IntegerConvert to integer; null on failure
toFloat(val)FloatConvert to float; null on failure

Examples

RETURN abs(-5)          -- 5
RETURN round(3.567, 2)  -- 3.57
RETURN sqrt(16)         -- 4.0
RETURN rand()           -- e.g. 0.7341...

Trigonometric Functions

SignatureReturnsDescription
sin(n)FloatSine (radians)
cos(n)FloatCosine (radians)
tan(n)FloatTangent (radians)
asin(n)FloatArcsine; result in radians
acos(n)FloatArccosine; result in radians
atan(n)FloatArctangent; result in radians
atan2(y, x)FloatTwo-argument arctangent
degrees(n)FloatRadians to degrees
radians(n)FloatDegrees to radians
cot(n)FloatCotangent
haversin(n)FloatHalf the versine of n
sinh(n)FloatHyperbolic sine
cosh(n)FloatHyperbolic cosine
tanh(n)FloatHyperbolic tangent
coth(n)FloatHyperbolic cotangent
isNaN(n)Booleantrue if n is NaN

Examples

RETURN degrees(pi())   -- 180.0
RETURN atan2(1.0, 1.0) -- 0.7853...

List Functions

SignatureReturnsDescription
size(list)IntegerNumber of elements
head(list)AnyFirst element; null if empty
tail(list)ListAll elements except the first; empty list if input has 0 or 1 elements
last(list)AnyLast element; null if empty
range(start, end)List<Integer>Inclusive integer range with step 1
range(start, end, step)List<Integer>Inclusive integer range with given step
collect(expr)ListAggregate: collect non-null values into a list
keys(node_or_map)List<String>Property key names of a node, relationship, or map
reduce(acc = init, x IN list | expr)AnyFold list into single value
[expr FOR x IN list]ListList comprehension without filter
[expr FOR x IN list WHERE cond]ListList comprehension with filter

Examples

RETURN range(1, 5)                          -- [1, 2, 3, 4, 5]
RETURN range(0, 10, 2)                      -- [0, 2, 4, 6, 8, 10]
RETURN head([1, 2, 3])                      -- 1
RETURN tail([1, 2, 3])                      -- [2, 3]
RETURN reduce(total = 0, x IN [1,2,3] | total + x) -- 6
RETURN [x * 2 FOR x IN [1,2,3] WHERE x > 1]        -- [4, 6]

Aggregation Functions

Aggregation functions collapse multiple rows into one. They are valid in RETURN and WITH.

SignatureReturnsDescription
count(expr)IntegerCount of non-null values
count(*)IntegerCount of rows
sum(expr)NumberSum of numeric values
avg(expr)FloatArithmetic mean of numeric values
min(expr)AnyMinimum value
max(expr)AnyMaximum value
collect(expr)ListList of non-null values
stdev(expr)FloatSample standard deviation
stdevp(expr)FloatPopulation standard deviation

Examples

MATCH (n:Person) RETURN count(n), avg(n.age), collect(n.name)
MATCH (n:Person) RETURN count(*) AS total

Entity Functions

SignatureReturnsDescription
id(entity)IntegerInternal numeric ID of a node or relationship
elementId(entity)StringString form of internal ID
labels(node)List<String>All labels of a node
type(rel)StringRelationship type name
properties(entity)MapAll properties as a map
startNode(rel)NodeSource node of a relationship
endNode(rel)NodeTarget node of a relationship
nodes(path)List<Node>Ordered list of nodes in a path
relationships(path)List<Relationship>Ordered list of relationships in a path
length(path)IntegerNumber of relationships in a path

Examples

MATCH (n:Person) RETURN id(n), labels(n)
MATCH ()-[r]->() RETURN type(r)
MATCH p = (a)-[*]->(b) RETURN length(p), nodes(p)

Type Conversion Functions

SignatureReturnsDescription
toString(val)StringConvert to string; error on unconvertible types
toInteger(val)IntegerConvert to integer; error on unconvertible types
toFloat(val)FloatConvert to float; error on unconvertible types
toBoolean(val)BooleanConvert to boolean; error on unconvertible types
toStringOrNull(val)String | nullConvert to string; null on failure
toIntegerOrNull(val)Integer | nullConvert to integer; null on failure
toFloatOrNull(val)Float | nullConvert to float; null on failure
toBooleanOrNull(val)Boolean | nullConvert to boolean; null on failure
valueType(val)StringReturns a string naming the Cypher type: "INTEGER", "FLOAT", "STRING", "BOOLEAN", "NULL", "LIST", "MAP", "NODE", "RELATIONSHIP", "PATH"

Examples

RETURN toInteger('42')         -- 42
RETURN toFloatOrNull('abc')    -- null
RETURN valueType(3.14)         -- 'FLOAT'
RETURN toBoolean('true')       -- true

Temporal Functions

SignatureReturnsDescription
date({year, month, day})DateConstruct a date
time({hour, minute, second})TimeConstruct a time
datetime({year, month, day, hour, minute, second})DateTimeConstruct a datetime
localdatetime({year, month, day, hour, minute, second})LocalDateTimeConstruct a local datetime (no timezone)
duration({days, hours, minutes, seconds})DurationConstruct a duration; all fields optional
datetime.fromepoch(seconds)DateTimeDateTime from Unix epoch seconds
datetime.fromepochmillis(ms)DateTimeDateTime from Unix epoch milliseconds
duration.inDays(d1, d2)DurationDuration between two dates in days
duration.inSeconds(d1, d2)DurationDuration between two datetimes in seconds
date.truncate(unit, date)DateTruncate date to unit: 'year', 'month', 'week', 'day'

Examples

RETURN date({year: 2024, month: 3, day: 15})
RETURN datetime.fromepoch(1700000000)
RETURN duration({days: 7, hours: 12})
RETURN date.truncate('month', date({year: 2024, month: 3, day: 15}))

Spatial Functions

SignatureReturnsDescription
point({x, y})Point2D Cartesian point
point({x, y, z})Point3D Cartesian point
point({latitude, longitude})Point2D geographic point (WGS-84)
point({latitude, longitude, height})Point3D geographic point (WGS-84)
distance(p1, p2)FloatDistance between two points (meters for geographic, units for Cartesian)
point.withinBBox(point, lowerLeft, upperRight)Booleantrue if point is inside bounding box

Examples

RETURN point({x: 1.0, y: 2.0})
RETURN distance(point({latitude: 48.8, longitude: 2.3}), point({latitude: 51.5, longitude: -0.1}))
RETURN point.withinBBox(
  point({x: 5, y: 5}),
  point({x: 0, y: 0}),
  point({x: 10, y: 10})
)  -- true

Predicate Functions

SignatureReturnsDescription
exists(expr)Booleantrue if the property or pattern exists and is not null
exists{pattern}Booleantrue if the pattern matches at least one result (full pattern syntax)
coalesce(v1, v2, ...)AnyFirst non-null argument; null if all arguments are null
nullIf(v1, v2)Any | nullReturns null if v1 = v2; otherwise returns v1

Examples

MATCH (n:Person) WHERE exists(n.email) RETURN n.name
MATCH (n:Person) WHERE exists{(n)-[:KNOWS]->(:Person)} RETURN n.name
RETURN coalesce(null, null, 'default')   -- 'default'
RETURN nullIf(5, 5)                      -- null
RETURN nullIf(5, 6)                      -- 5

CASE Expressions

Simple form

CASE expr
  WHEN value1 THEN result1
  WHEN value2 THEN result2
  ELSE default
END

Generic form

CASE
  WHEN condition1 THEN result1
  WHEN condition2 THEN result2
  ELSE default
END

ELSE is optional; omitting it returns null for unmatched rows.

Examples

MATCH (n:Person)
RETURN CASE n.role
  WHEN 'admin' THEN 'Administrator'
  WHEN 'mod'   THEN 'Moderator'
  ELSE 'User'
END AS roleLabel
MATCH (n:Person)
RETURN CASE
  WHEN n.age < 18 THEN 'minor'
  WHEN n.age < 65 THEN 'adult'
  ELSE 'senior'
END AS ageGroup

Graph Algorithm Functions

Called inside Cypher queries using CALL syntax or inline. See Graph Algorithms for full parameter and return type documentation.

SignatureDescription
pageRank([damping, iterations])PageRank centrality
labelPropagation([iterations])Label propagation community detection
louvain([resolution])Louvain modularity community detection
dijkstra(source, target[, weight_property])Weighted shortest path
astar(source, target[, lat_prop, lon_prop])A* heuristic shortest path
degreeCentrality()In/out/total degree per node
betweennessCentrality()Betweenness centrality per node
closenessCentrality()Closeness centrality per node
eigenvectorCentrality([iterations])Eigenvector centrality per node
weaklyConnectedComponents()WCC component assignment
stronglyConnectedComponents()SCC component assignment
bfs(start[, max_depth])Breadth-first traversal
dfs(start[, max_depth])Depth-first traversal
nodeSimilarity([node1, node2, threshold, top_k])Jaccard similarity
knn(node, k)k-nearest neighbors by similarity
triangleCount()Triangle count and clustering coefficient per node
apsp()All-pairs shortest paths
shortestPath(pattern)Shortest path as a path value