id

id() returns the id of a vertex or edge.

Syntax: id(expression)

Returns:

  1. An agtype integer

Arguments:

Name Description
expression An expression that returns a vertex or edge.

Considerations:

Query:

  1. SELECT *
  2. FROM cypher('graph_name', $$
  3. MATCH (a)
  4. RETURN id(a)
  5. $$) 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:

  1. An agtype integer

Arguments:

Name Description
expression An expression that evaluates to an edge.

Considerations:

Query:

  1. SELECT *
  2. FROM cypher('graph_name', $$
  3. MATCH ()-[e]->()
  4. RETURN start_id(e)
  5. $$) 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:

  1. An agtype integer

Arguments:

Name Description
expression An expression that evaluates to an edge.

Query:

  1. SELECT *
  2. FROM cypher('graph_name', $$
  3. MATCH ()-[e]->()
  4. RETURN end_id(e)
  5. $$) 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:

  1. An agtype string

Arguments:

Name Description
edge An expression that evaluates to an edge.

Considerations:

Query:

  1. SELECT *
  2. FROM cypher('graph_name', $$
  3. MATCH ()-[e]->()
  4. RETURN type(e)
  5. $$) 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:

  1. An agtype map.

Arguments:

Name Description
Expression An expression that returns a vertex, an edge, or an agtype map.

Considerations:

  • properties(null) returns null.

Query:

  1. SELECT *
  2. FROM cypher('graph_name', $$
  3. CREATE (p:Person {name: 'Stefan', city: 'Berlin'})
  4. RETURN properties(p)
  5. $$) 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:

  1. 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) returns null.
  • If the first element in the list is null, head(list) will return null.

Query

  1. SELECT *
  2. FROM cypher('graph_name', $$
  3. MATCH (a)
  4. WHERE a.name = 'Eskil'
  5. RETURN a.array, head(a.array)
  6. $$) 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:

  1. 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) returns null.
  • If the last element in the list is null, last(list) will return null.

Query

  1. SELECT *
  2. FROM cypher('graph_name', $$
  3. MATCH (a)
  4. WHERE a.name = 'Eskil'
  5. RETURN a.array, last(a.array)
  6. $$) 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:

  1. An agtype integer.

Arguments:

Name Description
path An expression that returns a path.

Considerations: length(null) returns null.

Query

  1. SELECT *
  2. FROM cypher('graph_name', $$
  3. MATCH p = (a)-[]->(b)-[]->(c)
  4. WHERE a.name = 'Alice'
  5. RETURN length(p)
  6. $$) 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:

  1. An agtype integer.

Arguments:

Name Description
list An expression that returns a list.

Considerations:

  • size(null) returns null.

Query

  1. SELECT *
  2. FROM cypher('graph_name', $$
  3. RETURN size(['Alice', 'Bob'])
  4. $$) 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:

  1. A vertex.

Arguments:

Name Description
edge An expression that returns an edge.

Considerations:

  • startNode(null) returns null.

Query

  1. SELECT *
  2. FROM cypher('graph_name', $$
  3. MATCH (x:Developer)-[r]-()
  4. RETURN startNode(r)
  5. $$) 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:

  1. A vertex.

Arguments:

Name Description
edge An expression that returns an edge.

Considerations:

  • endNode(null) returns null.

Query

  1. SELECT *
  2. FROM cypher('graph_name', $$
  3. MATCH (x:Developer)-[r]-()
  4. RETURN endNode(r)
  5. $$) 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:

  1. An agtype integer.

Considerations:

  • timestamp() will return the same value during one entire query, even for long-running queries.

Query

  1. SELECT *
  2. FROM cypher('graph_name', $$
  3. RETURN timestamp()
  4. $$) 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:

  1. An agtype boolean.

Arguments:

Name Description
expression An expression that returns a boolean or string value.

Considerations:

  • toBoolean(null) returns null.
  • If expression is a boolean value, it will be returned unchanged.
  • If the parsing fails, null will be returned.

Query

  1. SELECT *
  2. FROM cypher('graph_name', $$
  3. RETURN toBoolean('TRUE'), toBoolean('not a boolean')
  4. $$) 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:

  1. A float.
Name Description
expression An expression that returns an agtype number or agtype string value.

Considerations:

  • toFloat(null) returns null.
  • If expression is a floating point number, it will be returned unchanged.
  • If the parsing fails, null will be returned.

Query

  1. SELECT *
  2. FROM cypher('graph_name', $$
  3. RETURN toFloat('11.5'), toFloat('not a number')
  4. $$) 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:

  1. An agtype integer.

Arguments

Name Description
expression An expression that returns an agtype number or agtype string value.

Considerations:

  • toInteger(null) returns null.
  • If expression is an integer value, it will be returned unchanged.
  • If the parsing fails, null will be returned.

Query

  1. SELECT *
  2. FROM cypher('graph_name', $$
  3. RETURN toInteger('42'), toInteger('not a number')
  4. $$) 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:

  1. 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:

  • null will be returned if all the arguments are null.

Query

  1. SELECT *
  2. FROM cypher('graph_name', $$
  3. MATCH (a)
  4. WHERE a.name = 'Alice'
  5. RETURN coalesce(a.hairColor, a.eyes), a.hair_color, a.eyes
  6. $$) as (color agtype, hair_color agtype, eyes agtype);

Result

color hair_color eyes
“brown” NULL “Brown”
1 row(s) returned