id
id() returns the id of a vertex or edge.
Syntax: id(expression)
Returns:
An agtype integer
Arguments:
| Name | Description |
| expression | An expression that returns a vertex or edge. |
Considerations:
Query:
SELECT *FROM cypher('graph_name', $$MATCH (a)RETURN id(a)$$) as (id agtype);
Results
| id |
| 0 |
| 1 |
| 2 |
| 3 |
| 4 row(s) returned |
start_id
start_id() returns the id of the vertex that is the starting vertex for the edge.
Syntax: start_id(expression)
Returns:
An agtype integer
Arguments:
| Name | Description |
| expression | An expression that evaluates to an edge. |
Considerations:
Query:
SELECT *FROM cypher('graph_name', $$MATCH ()-[e]->()RETURN start_id(e)$$) as (start_id agtype);
Results
| start_id |
| 0 |
| 1 |
| 2 |
| 3 |
| 4 row(s) returned |
end_id
end_id() returns the id of the vertex that is the ending vertex for the edge.
Syntax: end_id(expression)
Returns:
An agtype integer
Arguments:
| Name | Description |
| expression | An expression that evaluates to an edge. |
Query:
SELECT *FROM cypher('graph_name', $$MATCH ()-[e]->()RETURN end_id(e)$$) as (end_id agtype);
Results
| end_id |
| 4 |
| 5 |
| 6 |
| 7 |
| 4 row(s) returned |
type
type() returns the string representation of the edge type.
Syntax: type(edge)
Returns:
An agtype string
Arguments:
| Name | Description |
| edge | An expression that evaluates to an edge. |
Considerations:
Query:
SELECT *FROM cypher('graph_name', $$MATCH ()-[e]->()RETURN type(e)$$) as (type agtype);
Results
| type |
| “KNOWS” |
| “KNOWS” |
| 2 row(s) returned |
properties
Returns an agtype map containing all the properties of a vertex or edge. If the argument is already a map, it is returned unchanged.
Syntax: properties(expression)
Returns:
An agtype map.
Arguments:
| Name | Description |
| Expression | An expression that returns a vertex, an edge, or an agtype map. |
Considerations:
properties(null)returnsnull.
Query:
SELECT *FROM cypher('graph_name', $$CREATE (p:Person {name: 'Stefan', city: 'Berlin'})RETURN properties(p)$$) as (type agtype);
Results:
| properties |
| {name: “Stefan”; city: “Berlin”} |
| 1 row(s) returned |
head
returns the first element in an agtype list.
Syntax: head(list)
Returns:
The type of the value returned will be that of the first element of the list.
Arguments:
| Name | Description |
| List | An expression that returns a list |
Considerations:
head(null)returnsnull.- If the first element in the list is
null,head(list)will returnnull.
Query
SELECT *FROM cypher('graph_name', $$MATCH (a)WHERE a.name = 'Eskil'RETURN a.array, head(a.array)$$) as (lst agtype, lst_head agtype);
The first element in the list is returned.
Result:
| lst | lst_head |
| [“one”,”two”,”three”] | “one” |
| 1 row(s) returned | |
last
returns the last element in an agtype list.
Syntax: last(list)
Returns:
The type of the value returned will be that of the last element of the list.
Arguments:
| Name | Description |
| List | An expression that returns a list |
Considerations:
tail(null)returnsnull.- If the last element in the list is
null,last(list)will returnnull.
Query
SELECT *FROM cypher('graph_name', $$MATCH (a)WHERE a.name = 'Eskil'RETURN a.array, last(a.array)$$) as (lst agtype, lst_tail agtype);
The first element in the list is returned.
Result:
| lst | lst_tail |
| [“one”,”two”,”three”] | “three” |
| 1 row(s) returned | |
length
length() returns the length of a path.
Syntax: length(path)
Returns:
An agtype integer.
Arguments:
| Name | Description |
| path | An expression that returns a path. |
Considerations: length(null) returns null.
Query
SELECT *FROM cypher('graph_name', $$MATCH p = (a)-[]->(b)-[]->(c)WHERE a.name = 'Alice'RETURN length(p)$$) as (length_of_path agtype);
The length of the path p is returned.
Results:
| length_of_path |
| 2 |
| 2 |
| 2 |
| 3 row(s) returned |
size
size() returns the length of a list.
Syntax: size(list)
Returns:
An agtype integer.
Arguments:
| Name | Description |
| list | An expression that returns a list. |
Considerations:
size(null)returnsnull.
Query
SELECT *FROM cypher('graph_name', $$RETURN size(['Alice', 'Bob'])$$) as (size_of_list agtype);
The length of the path p is returned.
Results:
| size_of_list |
| 2 |
| 1 row(s) returned |
startNode
startNode() returns the start node of an edge.
Syntax: startNode(edge)
Returns:
A vertex.
Arguments:
| Name | Description |
| edge | An expression that returns an edge. |
Considerations:
startNode(null)returnsnull.
Query
SELECT *FROM cypher('graph_name', $$MATCH (x:Developer)-[r]-()RETURN startNode(r)$$) as (v agtype);
Result
| v |
| Node[0]{name:”Alice”,age:38,eyes:”brown”} |
| Node[0]{name:”Alice”,age:38,eyes:”brown”} |
| 2 row(s) returned |
endNode
endNode() returns the start node of an edge.
Syntax: endNode(edge)
Returns:
A vertex.
Arguments:
| Name | Description |
| edge | An expression that returns an edge. |
Considerations:
endNode(null)returnsnull.
Query
SELECT *FROM cypher('graph_name', $$MATCH (x:Developer)-[r]-()RETURN endNode(r)$$) as (v agtype);
Result
| v |
| Node[2]{name:”Charlie”,age:53,eyes:”green”} |
| Node[1]{name:”Bob”,age:25,eyes:”blue”} |
| 2 row(s) returned |
timestamp
timestamp() returns the difference, measured in milliseconds, between the current time and midnight, January 1, 1970 UTC.
Syntax: timestamp()
Returns:
An agtype integer.
Considerations:
timestamp()will return the same value during one entire query, even for long-running queries.
Query
SELECT *FROM cypher('graph_name', $$RETURN timestamp()$$) as (t agtype);
The time in milliseconds is returned.
Results:
| t |
| 1613496720760 |
| 1 row(s) returned |
toBoolean
toBoolean() converts a string value to a boolean value.
Syntax: toBoolean(expression)
Returns:
An agtype boolean.
Arguments:
| Name | Description |
| expression | An expression that returns a boolean or string value. |
Considerations:
toBoolean(null)returnsnull.- If expression is a boolean value, it will be returned unchanged.
- If the parsing fails,
nullwill be returned.
Query
SELECT *FROM cypher('graph_name', $$RETURN toBoolean('TRUE'), toBoolean('not a boolean')$$) as (a_bool agtype, not_a_bool agtype);
Result:
| a_bool | not_a_bool |
| true | NULL |
| 1 row(s) returned | |
toFloat
toFloat() converts an integer or string value to a floating point number.
Syntax: toFloat(expression)
Returns:
A float.
| Name | Description |
| expression | An expression that returns an agtype number or agtype string value. |
Considerations:
toFloat(null)returnsnull.- If expression is a floating point number, it will be returned unchanged.
- If the parsing fails,
nullwill be returned.
Query
SELECT *FROM cypher('graph_name', $$RETURN toFloat('11.5'), toFloat('not a number')$$) as (a_float agtype, not_a_float agtype);
Result:
| a_float | not_a_float |
| 11.5 | NULL |
| 1 row(s) returned | |
toInteger
toInteger() converts a floating point or string value to an integer value.
Syntax: toInteger(expression)
Returns:
An agtype integer.
Arguments
| Name | Description |
| expression | An expression that returns an agtype number or agtype string value. |
Considerations:
toInteger(null)returnsnull.- If expression is an integer value, it will be returned unchanged.
- If the parsing fails,
nullwill be returned.
Query
SELECT *FROM cypher('graph_name', $$RETURN toInteger('42'), toInteger('not a number')$$) as (an_integer agtype, not_an_integer agtype);
Result:
| an_integer | not_an_integer |
| 42 | NULL |
| 1 row(s) returned | |
coalesce
coalesce() returns the first non-null value in the given list of expressions.
Syntax:coalesce(expression [, expression]*)
Returns:
The type of the value returned will be that of the first non-null expression.
Arguments:
| Name | Description |
| expression | An expression which may return null. |
Considerations:
nullwill be returned if all the arguments are null.
Query
SELECT *FROM cypher('graph_name', $$MATCH (a)WHERE a.name = 'Alice'RETURN coalesce(a.hairColor, a.eyes), a.hair_color, a.eyes$$) as (color agtype, hair_color agtype, eyes agtype);
Result
| color | hair_color | eyes |
| “brown” | NULL | “Brown” |
| 1 row(s) returned | ||
