Scalar Functions

id

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

Syntax:id(expression)

Returns:

An agtype integer

Arguments:

Considerations:

Query:

SELECT *
FROM cypher('graph_name', $$
    MATCH (a)
    RETURN id(a)
$$) as (id agtype);

Results

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:

Considerations:

Query:

SELECT *
FROM cypher('graph_name', $$
    MATCH ()-[e]->()
    RETURN start_id(e)
$$) as (start_id agtype);

Results

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:

Query:

SELECT *
FROM cypher('graph_name', $$
    MATCH ()-[e]->()
    RETURN end_id(e)
$$) as (end_id agtype);

Results

type

type() returns the string representation of the edge type

Syntax: type(edge)

Returns:

An agtype string

Arguments:

Considerations:

Query:

SELECT *
FROM cypher('graph_name', $$
    MATCH ()-[e]->()
    RETURN type(e)
$$) as (type agtype);

Results

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:

Considerations:

  • properties(null) returns null.

Query:

SELECT *
FROM cypher('graph_name', $$
    CREATE (p:Person {name: 'Stefan', city: 'Berlin'})
    RETURN properties(p)
$$) as (type agtype);

Results:

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:

Considerations:

  • head(null) returns null.
  • If the first element in the list is null, head(list) will return null.

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:

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:

Considerations:

  • tail(null) returns null.
  • If the last element in the list is null, last(list) will return null.

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:

length

length() returns the length of a path.

Syntax: length(path)

Returns:

An agtype Integer.

Arguments:

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:

size

size() returns the length of a list.

Syntax:size(list)

Returns:

An agtype Integer.

Arguments:

Considerations:

  • size(null) returns null.

Query

SELECT *
FROM cypher('graph_name', $$
    RETURN size(['Alice', 'Bob'])
$$) as (size_of_list agtype);

The length of the path p is returned.

Results:

startNode

startNode() returns the start node of an edge.

Syntax:startNode(edge)

Returns:

A vertex.

Arguments:

Considerations:

  • startNode(null) returns null.

Query

SELECT *
FROM cypher('graph_name', $$
    MATCH (x:Developer)-[r]-()
    RETURN startNode(r)
$$) as (v agtype);

Result

endNode

endNode() returns the start node of an edge.

Syntax: endNode(edge)

Returns:

A vertex.

Arguments:

Considerations:

  • endNode(null) returns null.

Query

SELECT *
FROM cypher('graph_name', $$
    MATCH (x:Developer)-[r]-()
    RETURN endNode(r)
$$) as (v agtype);

Result

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:

toBoolean

toBoolean() converts a string value to a boolean value.

Syntax: toBoolean(expression)

Returns:

An agtype Boolean.

Arguments:

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

SELECT *
FROM cypher('graph_name', $$
    RETURN toBoolean('TRUE'), toBoolean('not a boolean')
$$) as (a_bool agtype, not_a_bool agtype);

Result:

toFloat

toFloat() converts an integer or string value to a floating point number.

Syntax:toFloat(expression)

Returns:A Float.

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

SELECT *
FROM cypher('graph_name', $$
    RETURN toFloat('11.5'), toFloat('not a number')
$$) as (a_float agtype, not_a_float agtype);

Result:

toInteger

toInteger() converts a floating point or string value to an integer value.

Syntax:toInteger(expression)

Returns:

An agtype Integer.

Arguments

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

SELECT *
FROM cypher('graph_name', $$
     RETURN toInteger('42'), toInteger('not a number')
$$) as (an_integer agtype, not_an_integer agtype);

Result:

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:

Considerations:

  • null will 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