Skip to main content

Built-in Functions in LoraDB

Function names are case-insensitive; canonical camelCase is shown on each page. Unknown names and wrong arity are rejected at analysis time (Unknown function 'foo', WrongArity).

Most functions propagate null — any null argument makes the result null. The exceptions are the aggregates, coalesce, timestamp, pi, e, and rand.

Categories

CategoryExamplesReference
Aggregationcount, sum, collect, percentileContAggregation
StringtoLower, split, substring, replaceString
Mathabs, sqrt, sin, log, randMath
Listsize, head, range, reduceList
Temporaldate, datetime, duration.betweenTemporal
Spatialpoint, distanceSpatial
Vectorvector, vector.similarity.cosine, vector.similarity.euclidean, vector_distance, vector_norm, vector_dimension_count, toIntegerList, toFloatListVector
Pathlength, nodes, relationshipsPaths

Entity introspection

FunctionTakesReturns
id(x)node | relationshipInt — internal id
labels(n)nodeList<String>
type(r)relationshipString — rel type
keys(x)node | rel | mapList<String>
properties(x)node | rel | mapMap
MATCH (u:User)-[r:FOLLOWS]->(v:User)
RETURN id(u), labels(u), type(r), keys(u), properties(u)

Common uses

// Dump every property on a node as a map
MATCH (u:User {id: $id}) RETURN properties(u)

// Discover which labels a node carries
MATCH (n) WHERE id(n) = $raw_id RETURN labels(n)

// Inspect the type of a matched edge
MATCH (a)-[r]->(b) RETURN type(r), count(*) ORDER BY count(*) DESC

// Avoid duplicate pair rows
MATCH (a)-[:KNOWS]-(b) WHERE id(a) < id(b) RETURN a, b

See Graph model → Identity for why id() is opaque.

Type conversion and checking

FunctionBehaviour
toString(x)any → String; nullnull
toInteger(x) / toInt(x)Int/Float/String/BoolInt or null
toFloat(x)Int/Float/StringFloat or null
toBoolean(x) / toBooleanOrNull(x)Bool/String/IntBool or null
valueType(x)name of the value's type, e.g. "INTEGER", "LIST<T>"
coalesce(a, b, )first non-null argument
timestamp()current Unix time in milliseconds
RETURN toInteger('42'),                         -- 42
toInteger('abc'), -- null
toFloat(42), -- 42.0
coalesce(null, null, 'fallback'), -- 'fallback'
valueType(1), -- 'INTEGER'
valueType([1, 2, 3]), -- 'LIST<INTEGER>'
valueType(date('2024-01-15')) -- 'DATE'

coalesce recipes

// Default a missing property
MATCH (p:Person) RETURN p.name, coalesce(p.nickname, p.name) AS display

// Cascade through several optional fields
RETURN coalesce($phone, $email, 'unknown') AS contact

// Replace null in ordering
MATCH (p:Person)
RETURN p.name, coalesce(p.rank, 999999) AS rank_for_sort
ORDER BY rank_for_sort

For multi-branch logic with arbitrary predicates per branch (not just "first non-null"), use CASE.

valueType recipes

// Filter a heterogeneous list to numbers only
MATCH (n)
WHERE all(x IN n.values WHERE valueType(x) = 'INTEGER')
RETURN n

// Group by runtime type
UNWIND [1, 'two', 3.0, true, null] AS x
RETURN valueType(x) AS t, count(*) AS n
ORDER BY t

timestamp

Wall-clock milliseconds since the Unix epoch.

MERGE (c:Counter {name: 'events'})
ON CREATE SET c.first_seen = timestamp()
SET c.last_seen = timestamp()

See Data Types for every valueType return value and for how each type maps between LoraDB and host languages.

Null propagation — the common thread

Most functions return null when any argument is null. A small handful don't, so they're worth memorising:

  • Aggregates (count, sum, …) skip null inputs (except count(*), which counts rows).
  • coalesce(a, b, …) — returns the first non-null argument.
  • timestamp(), pi(), e(), rand() — take no arguments.

Everywhere else, expect null in → null out. This is what makes IS NULL / IS NOT NULL essential over = null.

Quick lookup

Finding the right function for a task:

I want to…Reach for
Pick the first non-null valuecoalesce(a, b, )
Branch on arbitrary conditionsCASE WHEN THEN END
Count rows matching a conditioncount(CASE WHEN THEN 1 END)
Concatenate a list into a stringreduce over split / collect
Current time (ms)timestamp()
Current calendar daydate()
Name of a value's typevalueType(x)
Internal id of a node / relid(x)
Total order over temporal values<, <=, >, >= — see Ordering
Cartesian or geodesic distancedistance(a, b)
Score a VECTOR against a query vectorvector.similarity.cosine(v, $q)
Signed distance under a metricvector_distance(a, b, EUCLIDEAN)
Magnitude of a VECTORvector_norm(v, EUCLIDEAN)
Dimension of a VECTORvector_dimension_count(v) or size(v)
Convert VECTOR coordinates back to a LISTtoIntegerList(v) / toFloatList(v)

Not supported

  • APOC-style utilities (apoc.*) — no compatibility layer.
  • Procedures (CALL db.labels() etc.) — rejected at analysis time.
  • User-defined functions — no registration surface.

Full list in Limitations.

See also