DEV Community

Talha Munir 🇵🇸
Talha Munir 🇵🇸

Posted on

Scalar functions in Apache age

Scalar functions in Apache age are mentioned below:

id

id() returns the id of the vertex or an edge. It returns an agtype integer.

Query:

Query for usage of id is as under:

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

Start_id():

Start_id returns the id of the starting vertex or an edge. It also returns an agtype integer.

Query:

Query for usage of start_id() is as under

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

The query returns the start id of all the vertex and edges.

end_id:

End_id returns the id of such vertex that are the ending vertexes for the edges. It also returns an agtype integer.

Query:

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

Type:

Type() returns the string representation of the edge type. It returns an agtype string.

Query:

Query for the usage of type function is as below:

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

Properties():

Returns an agtype map which contains all the properties of a vertex or an edge. If the argument is a map then it is returned unchanged.

Query:

Query for the usage of properties is as under.

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

It returns the properties of the node p created in the same query.

Latest comments (0)