Scalar Functions

id()

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

Syntax: id(expression)

Returns:

An agtype integer.

Parameters:

Name Description
expression An expression that evaluates to a vertex or edge.

Query:

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

Result:

id
0
1
2
3
4 rows

start_id()

start_id() returns the internal identifier of the start vertex of an edge.

Syntax: start_id(expression)

Returns:

An agtype integer.

Parameters:

Name Description
expression An expression that evaluates to an edge.

Query:

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

Result:

start_id
0
1
2
3
4 rows

end_id()

end_id() returns the internal identifier of the end vertex of an edge.

Syntax: end_id(expression)

Returns:

An agtype integer.

Parameters:

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);

Result:

end_id
4
5
6
7
4 rows

type()

type() returns the type of an edge as a string.

Syntax: type(edge)

Returns:

An agtype string.

Parameters:

Name Description
edge An expression that evaluates to an edge.

Query:

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

Result:

type
"KNOWS"
"KNOWS"
2 rows

properties()

properties() returns an agtype map containing all properties of a vertex or edge. If the argument is already an agtype map, it is returned unchanged.

Syntax: properties(expression)

Returns:

An agtype map.

Parameters:

Name Description
expression An expression that evaluates to a vertex, edge, or agtype map.

Notes:

  • properties(null) returns null.

Query:

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

Result:

properties
{name: "Stefan", city: "Berlin"}
1 row

head()

head() returns the first element of an agtype list.

Syntax: head(list)

Returns:

The result has the same type as the first element of the list.

Parameters:

Name Description
list An expression that evaluates to a list.

Notes:

  • head(null) returns null.
  • If the first element of the list is null, head(list) returns 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);

Returns the first element of the list.

Result:

lst lst_head
["one","two","three"] "one"
1 row

last()

last() returns the last element of an agtype list.

Syntax: last(list)

Returns:

The result has the same type as the last element of the list.

Parameters:

Name Description
list An expression that evaluates to a list.

Notes:

  • last(null) returns null.
  • If the last element of the list is null, last(list) returns 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);

Returns the last element of the list.

Result:

lst lst_tail
["one","two","three"] "three"
1 row

length()

length() returns the number of relationships in a path.

Syntax: length(path)

Returns:

An agtype integer.

Parameters:

Name Description
path An expression that evaluates to a path.

Notes: 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);

Returns the length of path p.

Result:

length_of_path
2
2
2
3 rows

size()

size() returns the number of elements in an agtype list.

Syntax: size(list)

Returns:

An agtype integer.

Parameters:

Name Description
list An expression that evaluates to a list.

Notes: size(null) returns null.

Query:

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

Returns the length of the list.

Result:

size_of_list
2
1 row

startNode()

startNode() returns the start vertex of an edge.

[!CAUTION]
In YMatrix AGE, startNode() and endNode() may fail in distributed environments with:

ERROR: graphid cde <id> does not exist  

This occurs because the edge and its start vertex may reside on different segments. startNode() attempts to resolve the vertex by graphid, but the vertex may not be local to the current segment.

Workaround: Use start_id() or end_id() to retrieve the graphid, then explicitly MATCH the corresponding vertex.

Syntax: startNode(edge)

Returns:

A vertex.

Parameters:

Name Description
edge An expression that evaluates to an edge.

Notes:

  • startNode(null) returns null.

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 rows

endNode()

endNode() returns the end vertex of an edge.

Syntax: endNode(edge)

Returns:

A vertex.

Parameters:

Name Description
edge An expression that evaluates to an edge.

Notes:

  • endNode(null) returns null.

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 rows

timestamp()

timestamp() returns the difference, in milliseconds, between the current time and midnight UTC on January 1, 1970.

Syntax: timestamp()

Returns:

An agtype integer.

Notes:

  • timestamp() returns the same value throughout the entire query execution — even for long-running queries.

Query:

SELECT *
FROM cypher('graph_name', $$
    RETURN timestamp()
$$) as (t agtype);

Returns the timestamp in milliseconds.

Result:

t
1613496720760
1 row

toBoolean()

toBoolean() converts a string value to a Boolean.

Syntax: toBoolean(expression)

Returns:

An agtype Boolean.

Parameters:

Name Description
expression An expression that evaluates to a Boolean or string.

Notes:

  • toBoolean(null) returns null.
  • If expression is already a Boolean, it is returned unchanged.
  • On parse failure, returns null.

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

toFloat()

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

Syntax: toFloat(expression)

Returns:

A floating-point number.

Parameters:

Name Description
expression An expression that evaluates to an agtype numeric or string.

Notes:

  • toFloat(null) returns null.
  • If expression is already a floating-point number, it is returned unchanged.
  • On parse failure, returns null.

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

toInteger()

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

Syntax: toInteger(expression)

Returns:

An agtype integer.

Parameters:

Name Description
expression An expression that evaluates to an agtype numeric or string.

Notes:

  • toInteger(null) returns null.
  • If expression is already an integer, it is returned unchanged.
  • On parse failure, returns null.

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

coalesce()

coalesce() returns the first non-null value from a list of expressions.

Syntax: coalesce(expression [, expression]*)

Returns:

The result has the same type as the first non-null expression.

Parameters:

Name Description
expression An expression that may evaluate to null.

Notes:

  • If all arguments are null, coalesce() returns 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