
GQLINSERT (p1:Paper {_id:'P1', title:'Efficient Graph Search', score:6, author:'Alex'}), (p2:Paper {_id:'P2', title:'Optimizing Queries', score:9, author:'Alex'}), (p3:Paper {_id:'P3', title:'Path Patterns', score:7, author:'Zack'}), (p1)-[:Cites {weight:2}]->(p2), (p2)-[:Cites {weight:1}]->(p3)
Returns the first element in a list.
| Syntax | head(<list>) | ||
| Arguments | Name | Type | Description |
<list> | LIST | The target list | |
| Return Type | STRING | ||
GQLLET myList = ["a", 1, 2] RETURN head(myList)
Result: "a"
Returns the last element of a list.
| Syntax | last(<list>) | ||
| Arguments | Name | Type | Description |
<list> | LIST | The input list | |
| Return Type | Type of the last element | ||
GQLRETURN last([1, 2, 3])
Result: 3
Returns all elements of a list except the first.
| Syntax | tail(<list>) | ||
| Arguments | Name | Type | Description |
<list> | LIST | The input list | |
| Return Type | LIST | ||
GQLRETURN tail([1, 2, 3, 4])
Result: [2, 3, 4]
Returns the number of elements in a list.
| Syntax | size(<list>) | ||
| Arguments | Name | Type | Description |
<list> | LIST | The target list | |
| Return Type | UINT | ||
GQLLET myList = [1, 2, null, 3] RETURN size(myList)
Result:
| size(myList) |
|---|
| 4 |
Returns a list with elements in reversed order.
| Syntax | reverse(<list>) | ||
| Arguments | Name | Type | Description |
<list> | LIST | The input list | |
| Return Type | LIST | ||
GQLRETURN reverse([1, 2, 3])
Result: [3, 2, 1]
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 | ||
GQLLET myList = ["a", 1, 2] RETURN append(myList, "b")
Result: ["a",1,2,"b"]
Generates a list of integers from start to end (inclusive), with an optional step.
| Syntax | range(<start>, <end> [, <step>]) | ||
| Arguments | Name | Type | Description |
<start> | INT | Start value (inclusive) | |
<end> | INT | End value (inclusive) | |
<step> | INT | Step increment (default: 1) | |
| Return Type | LIST<INT> | ||
GQLRETURN range(1, 5), range(0, 10, 3)
Result: [1, 2, 3, 4, 5], [0, 3, 6, 9]
Returns true if a value exists in a specified list.
| Syntax | list_contains(<list>, <value>) | ||
| Arguments | Name | Type | Description |
<list> | LIST | The list to be checked | |
<value> | Any | The value to look for in <list> | |
| Return | 1 or 0 | ||
GQLLET myList = ["a", 1, 2] RETURN list_contains(myList, "b")
Result: false
Returns the union of two lists, producing a new list of elements from either input list. Duplicates are removed.
| Syntax | list_union(<list_1>, <list_2>) | ||
| Arguments | Name | Type | Description |
<list_1> | LIST | The first list | |
<list_2> | LIST | The second list | |
| Return Type | LIST | ||
GQLLET l1 = [1,2,2,3], l2 = [3,4,5] RETURN list_union(l1, l2)
Result: [1,2,3,4,5]
Returns the intersection of two lists, producing a new list of elements common to both. Duplicates are removed.
| 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 | ||
GQLLET l1 = [1,2,3,3], l2 = [3,3,4,5] RETURN intersection(l1, l2)
Result: [3]
Returns the difference between two lists, producing a new list of elements found in the first list but not in the second. Duplicates are removed.
| 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 | ||
GQLLET l1 = [1,2,2,3], l2 = [3,4,5] RETURN difference(l1, l2)
Result: [1,2]
Sorts a list.
| Syntax | list_sort(<list> [, <order> [, <nullOrder>]]) | ||
| Arguments | Name | Type | Description |
<list> | LIST | The input list | |
<order> | STRING | "asc" (default) or "desc" | |
<nullOrder> | STRING | "first" or "last" | |
| Return Type | LIST | ||
GQLRETURN list_sort([3, 1, 4, 1, 5])
Result: [1, 1, 3, 4, 5]
Filters a list of records, nodes, or edges by checking a property against a value using an operator.
| Syntax | list_filter(<list>, <propertyName>, <operator>, <value>) | ||
| Arguments | Name | Type | Description |
<list> | LIST | A list of maps, nodes, or edges | |
<propertyName> | STRING | The property name to filter on | |
<operator> | STRING | Comparison operator: `"="`, `">"`, `"<"`, `">="`, `"<="`, `"<>"` | |
<value> | Any | The value to compare against | |
| Return Type | LIST | ||
GQLMATCH (n:Paper) LET papers = collect_list(n) RETURN list_filter(papers, "score", ">", 7)
Result:
JSON[ {"id": "P2", "labels": ["Paper"], "properties": {"title": "Optimizing Queries", "score": 9, "author": "Alex"}} ]
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 | ||
GQLLET myList = [1,3,5] RETURN reduce(_sum = 0, item in myList | _sum + item) AS listSum
Result: 9
GQLMATCH p = ({_id: "P1"})-[edges]->{2}() RETURN reduce(total = 0, edge in edges | total + edge.weight)
Result: 3