UltipaDocs
Try Playground
  • Quick Start
  • Procedure Management
  • Parameters and Types
  • Control Flow
  • Data Operations
  • Iterators and Traversal
  • Parallel Execution
  • Built-in Functions
  • Expressions
  • Algorithm Examples
  1. Docs
  2. /
  3. Stored Procedures

Expressions

Complete reference for all expression types available in stored procedures.

Arithmetic Operators

OperatorDescriptionExample
+Additiona + b
-Subtractiona - b
*Multiplicationa * b
/Divisiona / b
%Moduloa % b
^Exponentiationa ^ b
Procedure Body Language
LET sum = x + y
LET ratio = count / total
LET remainder = i % 2
LET squared = x ^ 2

Comparison Operators

OperatorDescriptionExample
=Equala = b
<>Not equala <> b
!=Not equal (alias)a != b
<Less thana < b
>Greater thana > b
<=Less than or equala <= b
>=Greater than or equala >= b

Logical Operators

OperatorDescriptionExample
ANDLogical ANDa AND b
ORLogical ORa OR b
NOTLogical NOTNOT a
XORExclusive ORa XOR b
Procedure Body Language
IF age > 18 AND active = true {
    PRINT 'Active adult'
}

IF score > 0.9 OR rank < 10 {
    PRINT 'Notable'
}

IF NOT visited {
    node.visited = true
}

String Concatenation

Use || for string concatenation:

Procedure Body Language
LET greeting = 'Hello, ' || name || '!'
LET info = 'Count: ' || TOSTRING(count) || ', Score: ' || TOSTRING(score)

NULL Checks

ExpressionDescription
expr IS NULLTrue if value is NULL
expr IS NOT NULLTrue if value is not NULL
Procedure Body Language
IF node.email IS NOT NULL {
    PRINT node.email
}

IF path IS NULL {
    PRINT 'No path found'
}

IN / NOT IN

Check membership in a list:

Procedure Body Language
IF node._id IN ['alice', 'bob', 'charlie'] {
    PRINT 'Found known person'
}

IF label NOT IN excluded_labels {
    -- process
}

CASE Expression

Simple CASE

Procedure Body Language
LET category = CASE status
    WHEN 'active' THEN 'A'
    WHEN 'pending' THEN 'P'
    WHEN 'inactive' THEN 'I'
    ELSE 'U'
END

Searched CASE

Procedure Body Language
LET tier = CASE
    WHEN score > 0.9 THEN 'platinum'
    WHEN score > 0.7 THEN 'gold'
    WHEN score > 0.5 THEN 'silver'
    ELSE 'bronze'
END

List Comprehension

Transform

Procedure Body Language
-- [expr FOR var IN list]
LET doubled = [x * 2 IN RANGE(1, 6)]

-- [expr | var IN list]
LET names = [node.name | node IN friends]

Filter and Transform

Procedure Body Language
-- [expr FOR var IN list WHERE condition]
LET active_names = [node.name | node IN friends WHERE node.active = true]

-- With complex expressions
LET scores = [GET_SLICE_PROP(n._internal_id, 'rank') | n IN nodes WHERE OUT_DEGREE(n) > 5]

REDUCE

Aggregate a list into a single value:

Procedure Body Language
LET total = REDUCE(acc = 0, x IN numbers | acc + x)
LET product = REDUCE(acc = 1, x IN values | acc * x)

Subscript Access

List Indexing

Procedure Body Language
LET first = myList[0]
LET third = myList[2]

List Slicing

Procedure Body Language
LET sub = myList[1:3]    -- elements at index 1 and 2
LET head = myList[0:5]   -- first 5 elements

Map Access

Procedure Body Language
LET value = myMap['key']
LET name = record['name']

Property Access

Procedure Body Language
-- Node properties
LET name = node.name
LET id = node._id
LET internal = node._internal_id
LET labels = node._labels

-- Edge properties
LET weight = edge.weight
LET from = edge._from
LET to = edge._to

-- Path properties
LET len = path.length
LET nodes = path.nodes
LET edges = path.edges

Subquery Expression

Use a subquery as an expression to assign its result to a variable:

Procedure Body Language
LET result = (MATCH (n:Person WHERE n.age > 30) RETURN COUNT(n) AS cnt)

This returns the result of the inner query as a value.

EXISTS / NOT EXISTS

Check whether a subquery returns any results:

Procedure Body Language
IF EXISTS {
    MATCH (n)-[:KNOWS]->(m WHERE m.name = 'Alice')
} {
    PRINT 'Knows Alice'
}

IF NOT EXISTS {
    MATCH (n)-[:BLOCKED]->(m)
} {
    PRINT 'Not blocked'
}

MAP Expression

Transform each element of a list:

Procedure Body Language
LET result = MAP(x IN myList | x * 2)

Operator Precedence

From highest to lowest:

PrecedenceOperators
1 (highest). (property access), [] (subscript)
2^ (exponentiation)
3Unary -, NOT
4*, /, %
5+, -
6`
7=, <>, !=, <, >, <=, >=
8IS NULL, IS NOT NULL, IN, NOT IN
9AND
10XOR
11 (lowest)OR

Use parentheses to override default precedence:

Procedure Body Language
LET result = (a + b) * (c - d)
IF (x > 0 AND y > 0) OR z = 0 { ... }