Example Graph
The following examples run against this graph:

append()
Adds an element to the end of a list and returns the new list.
| Syntax | append(<list>, <elem>) |
||
| Arguments | Name | Type | Description |
<list> |
LIST |
The target list | |
<elem> |
Any | The element to be added | |
| Return Type | LIST |
||
LET myList = ["a", 1, 2]
RETURN append(myList, "b")
Result:
| append(myList, "b") |
|---|
| ["a",1,2,"b"] |
difference()
Returns the difference between two lists, producing a new list of elements found in the first input list but not in the second. Duplicates are included.
| Syntax | difference(<list_1>, <list_2>) |
||
| Arguments | Name | Type | Description |
<list_1> |
LIST |
The first list | |
<list_2> |
LIST |
The second list | |
| Return Type | LIST |
||
LET l1 = [1,2,2,3], l2 = [3,4,5]
RETURN difference(l1, l2)
Result:
| difference(l1, l2) |
|---|
| [1,2,2] |
elements()
Returns a list containing the nodes and edges that make up a path.
| Syntax | elements(<path>) |
||
| Arguments | Name | Type | Description |
<path> |
PATH |
The target path | |
| Return Type | LIST |
||
MATCH p = ()->()
LET items = elements(p)
FOR item IN items WITH ORDINALITY index
FILTER index %2 = 1
RETURN item
Result: item
_id |
_uuid | schema | values |
|---|---|---|---|
| P2 | Sys-gen | Course | {title: "Optimizing Queries", author: "Alex", score: 9} |
| P3 | Sys-gen | Course | {title: "Path Patterns", author: "Zack", score: 7} |
| P1 | Sys-gen | Course | {title: "Efficient Graph Search", author: "Alex", score: 6} |
| P2 | Sys-gen | Course | {title: "Optimizing Queries", author: "Alex", score: 9} |
head()
Returns the first element in a list.
| Syntax | head(<list>) |
||
| Arguments | Name | Type | Description |
<list> |
LIST |
The target list | |
| Return Type | STRING |
||
LET myList = ["a", 1, 2]
RETURN head(myList)
Result:
| head(myList) |
|---|
| a |
intersection()
Returns the intersection of two lists, producing a new list of elements common to both. Duplicates are included.
| Syntax | intersection(<list_1>, <list_2>) |
||
| Arguments | Name | Type | Description |
<list_1> |
LIST |
The first list | |
<list_2> |
LIST |
The second list | |
| Return Type | LIST |
||
LET l1 = [1,2,3,3], l2 = [3,3,4,5]
RETURN intersection(l1, l2)
Result:
| intersection(l1, l2) |
|---|
| [3,3] |
listContains()
Checks whether a specified element exists in a list, returning 1 for true and 0 for false.
| Syntax | listContains(<list>, <elem>) |
||
| Arguments | Name | Type | Description |
<list> |
LIST |
The list to be checked | |
<elem> |
Any | The element to look for in <list> |
|
| Return | 1 or 0 |
||
LET myList = ["a", 1, 2]
RETURN listContains(myList, "b")
Result:
| listContains(myList, "b") |
|---|
| 0 |
listUnion()
Returns the union of two lists, producing a new list of elements from either input list. Duplicates are removed.
| Syntax | listUnion(<list_1>, <list_2>) |
||
| Arguments | Name | Type | Description |
<list_1> |
LIST |
The first list | |
<list_2> |
LIST |
The second list | |
| Return Type | LIST |
||
LET l1 = [1,2,2,3], l2 = [3,4,5]
RETURN listUnion(l1, l2)
Result:
| listUnion(l1, l2) |
|---|
| [1,2,3,4,5] |
reduce()
Performs a calculation iteratively using each element in a list. With a specified intital value, the defined calculation takes the first element in the list as input.
| Syntax | reduce(<resAlias> = <initVal>, <elemAlias> in <list> | <calcExp>) |
||
| Arguments | Name | Type | Description |
<resAlias> |
/ | The alias representing the initial, intermediate and final calculation result | |
<initVal> |
/ | The initial value assigned to <resAlias> |
|
<elemAlias> |
/ | The alias representing each element in the list | |
<list> |
LIST |
The target list | |
<calcExp> |
/ | The calculation expression | |
| Return Type | STRING |
||
LET myList = [1,3,5]
RETURN reduce(_sum = 0, item in myList | _sum + item) AS listSum
Result:
| listSum |
|---|
| 9 |
MATCH p = ({_id: "P1"})-[edges]->{2}()
RETURN reduce(total = 0, edge in edges | total + edge.weight) as totalWeights
Result:
| totalWeights |
|---|
| 3 |
size()
Returns the number of elements in a list.
| Syntax | size(<list>) |
||
| Arguments | Name | Type | Description |
<list> |
LIST |
The target list | |
| Return Type | UINT |
||
LET myList = [1, 2, null, 3]
RETURN size(myList)
Result:
| size(myList) |
|---|
| 4 |
trim()
Removes a specified number of elements from the right end of the list.
| Syntax | trim(<list>, <num>) |
||
| Arguments | Name | Type | Description |
<list> |
LIST |
The list to be trimmed | |
<num> |
UINT |
An integer specifying the number of elements to be removed from the list | |
| Return Type | LIST |
||
LET myList = [1, 2, null, 3]
RETURN trim(myList, 2)
Result:
| TRIM(myList, 2) |
|---|
| [1,2] |