Skip to main content

Functions Reference

Graphmind includes 50+ built-in functions. This page lists them all with examples.

String Functions

FunctionDescriptionExample
toUpper(s)UppercasetoUpper("hello") -> "HELLO"
toLower(s)LowercasetoLower("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 substringreplace("hello", "l", "r") -> "herro"
substring(s, start, len)Extract substringsubstring("hello", 1, 3) -> "ell"
left(s, n)First n charactersleft("hello", 3) -> "hel"
right(s, n)Last n charactersright("hello", 3) -> "llo"
reverse(s)Reverse a stringreverse("hello") -> "olleh"
toString(v)Convert to stringtoString(42) -> "42"
size(s)String lengthsize("hello") -> 5

String function examples

MATCH (p:Person)
RETURN toUpper(p.name) AS upper_name,
size(p.name) AS name_length
MATCH (p:Person)
WHERE toLower(p.name) STARTS WITH "al"
RETURN p.name

Numeric Functions

FunctionDescriptionExample
abs(n)Absolute valueabs(-5) -> 5
ceil(n)Round upceil(2.3) -> 3.0
floor(n)Round downfloor(2.7) -> 2.0
round(n)Round to nearestround(2.5) -> 3.0
sqrt(n)Square rootsqrt(16) -> 4.0
sign(n)Sign (-1, 0, 1)sign(-5) -> -1
rand()Random float between 0 and 1rand() -> 0.7231...
randomUUID()Generate a random UUID v4 stringrandomUUID() -> "550e8400-e29b-..."
log(n)Natural logarithmlog(2.718) -> ~1.0
exp(n)Euler's number raised to powerexp(1) -> 2.718...
toInteger(v)Convert to integertoInteger("42") -> 42
toFloat(v)Convert to floattoFloat("3.14") -> 3.14

Numeric function examples

MATCH (p:Person)
RETURN p.name, abs(p.age - 30) AS distance_from_30
ORDER BY distance_from_30
MATCH (p:Person)
RETURN round(avg(p.age)) AS rounded_avg
-- Generate UUIDs
RETURN randomUUID() AS id1, randomUUID() AS id2

-- Use UUID when creating nodes (via SDK)
-- Python: db.query(f"CREATE (n:Person {{id: '{uuid.uuid4()}', name: 'Alice'}})")
-- Note: randomUUID() in CREATE properties requires WITH pattern:
-- WITH randomUUID() AS uid CREATE (n:Person {id: uid, name: 'Alice'})

List Functions

FunctionDescriptionExample
size(list)Number of elementssize([1,2,3]) -> 3
head(list)First elementhead([1,2,3]) -> 1
last(list)Last elementlast([1,2,3]) -> 3
tail(list)All except firsttail([1,2,3]) -> [2,3]
keys(node)Property keyskeys(n) -> ["name","age"]
range(start, end)Integer rangerange(1, 5) -> [1,2,3,4,5]
length(path)Length of a path (number of relationships)length(p) -> 3

List function examples

MATCH (p:Person)
RETURN p.name, keys(p) AS properties
UNWIND range(1, 10) AS i
RETURN i, i * i AS square

Node and Relationship Functions

FunctionDescriptionExample
id(n)Internal node/edge IDid(n) -> 42
labels(n)Node labelslabels(n) -> ["Person"]
type(r)Relationship typetype(r) -> "KNOWS"
exists(expr)Check if property existsexists(n.email) -> true
coalesce(a, b, ...)First non-null valuecoalesce(n.nick, n.name) -> "Alice"
properties(n)All properties as a mapproperties(n) -> {name: "Alice", age: 30}
nodes(path)List of nodes in a pathnodes(p) -> [node1, node2]
relationships(path)List of relationships in a pathrelationships(p) -> [rel1]
shortestPath(pattern)Find shortest path between nodesSee below
allShortestPaths(pattern)Find all shortest pathsSee below

Node function examples

-- Get all labels and their counts
MATCH (n)
RETURN labels(n) AS label, count(n) AS count
ORDER BY count DESC
-- Find nodes missing email
MATCH (p:Person)
WHERE NOT exists(p.email)
RETURN p.name
-- Display name with fallback
MATCH (p:Person)
RETURN coalesce(p.nickname, p.name) AS display_name

Shortest Path

-- Find the shortest path between two nodes
MATCH p = shortestPath((a:Person {name: "Alice"})-[*..10]-(b:Person {name: "Dave"}))
RETURN p

-- Find all shortest paths (may return multiple equal-length paths)
MATCH p = allShortestPaths((a:Person {name: "Alice"})-[*]-(b:Person {name: "Dave"}))
RETURN p

Properties Function

-- Return all properties of a node as a map
MATCH (p:Person {name: "Alice"})
RETURN properties(p)
-- {name: "Alice", age: 30, active: true}

Reduce

Fold a list into a single value with an accumulator:

WITH [1, 2, 3, 4, 5] AS numbers
RETURN reduce(total = 0, x IN numbers | total + x) AS sum
-- 15
MATCH (p:Person {name: "Alice"})-[:KNOWS]->(f)
WITH collect(f.name) AS friends
RETURN reduce(s = "", name IN friends | s + name + ", ") AS all_friends

Aggregate Functions

FunctionDescription
count(x)Count non-null values (or count(*) for all rows)
sum(x)Sum of numeric values
avg(x)Average of numeric values
min(x)Minimum value
max(x)Maximum value
collect(x)Collect values into a list

See Aggregations for detailed examples and grouping behavior.

Temporal Functions

FunctionDescriptionExample
date()Current datedate() -> 2026-03-20
date(string)Parse date from stringdate("2024-01-15")
date(map)Construct date from componentsdate({year: 2024, month: 1, day: 15})
datetime()Current date and timedatetime() -> 2026-03-20T14:30:00Z
datetime(string)Parse datetime from stringdatetime("2024-01-15T10:30:00")
datetime(map)Construct datetime from componentsdatetime({year: 2024, month: 1, day: 15, hour: 10})
duration(map)Construct a durationduration({days: 14, hours: 3})
duration(string)Parse ISO 8601 durationduration("P14DT3H")
timestamp()Current time as epoch millisecondstimestamp() -> 1710936000000
localdatetime()Current local datetime (no timezone)localdatetime() -> 2026-03-20T14:30:00
localdatetime(string)Parse local datetime from stringlocaldatetime("2024-01-15T10:30:00")
localdatetime(map)Construct from componentslocaldatetime({year: 2024, month: 1, day: 15})
localtime()Current local time (no timezone)localtime() -> 14:30:00
localtime(string)Parse local time from stringlocaltime("10:30:00")
localtime(map)Construct from componentslocaltime({hour: 10, minute: 30})
time()Current time (with timezone)time() -> 14:30:00Z
time(string)Parse time from stringtime("10:30:00")
time(map)Construct from componentstime({hour: 10, minute: 30})
note

localdatetime(), localtime(), and time() are implemented but internally store values as epoch milliseconds, same as datetime(). They are provided for OpenCypher compatibility.

Temporal function examples

RETURN date() AS today, datetime() AS now, timestamp() AS epoch_ms
RETURN date("2024-06-15") AS parsed_date,
datetime({year: 2024, month: 6, day: 15, hour: 12}) AS constructed
RETURN duration({days: 30}) AS one_month,
duration("P1Y2M") AS iso_duration

Predicate Functions

These functions test every element in a list against a condition.

FunctionDescription
all(x IN list WHERE predicate)True if predicate holds for all elements
any(x IN list WHERE predicate)True if predicate holds for at least one element
none(x IN list WHERE predicate)True if predicate holds for no elements
single(x IN list WHERE predicate)True if predicate holds for exactly one element

Predicate function examples

WITH [1, 2, 3, 4, 5] AS numbers
RETURN all(x IN numbers WHERE x > 0) AS all_positive,
any(x IN numbers WHERE x > 4) AS has_large,
none(x IN numbers WHERE x < 0) AS none_negative,
single(x IN numbers WHERE x = 3) AS exactly_one_three

Unsupported Functions

These OpenCypher functions are not yet implemented:

  • split(s, delimiter) -- split string into list
  • log10(n), e(), pi() -- base-10 logarithm, mathematical constants
  • sin, cos, tan, asin, acos, atan, atan2 -- trigonometric functions
  • degrees(n), radians(n) -- angle conversion
  • elementId(n) -- element identifier (use id(n) instead)
  • startNode(r), endNode(r) -- start/end node of a relationship
  • point(map), distance(p1, p2) -- spatial functions
  • collect(DISTINCT x) -- distinct aggregation