In this blog we will discuss some of the predicate functions and then user defined functions.
Predicate functions
Predicates are boolean functions that return true or false for a given set of input. They are most commonly used to filter out subgraphs in the WHERE part of a query.
Some of the predicate functions are explained below:
Exists():
Exists here returns true if the specified property is existing in the graphs, node and relationships.
Syntax:
exists(property)
It returns an agtype boolean value.
Query:
SELECT *
FROM cypher('graph_name', $$
MATCH (n)
WHERE exists(n.surname)
RETURN n.first_name, n.last_name
$$) as (first_name agtype, last_name agtype);
Exists(path):
Exists(path) returns true if a path already exists there.
Syntax:
Exists(path)
Query:
SELECT *
FROM cypher('graph_name', $$
MATCH (n)
WHERE exists(n)-[]-(name: 'Willem Defoe')
RETURN n.full_name
$$) as (full_name agtype);
User Defined functions:
In apache age users can add their custom functions to age. When we use cypher function calls we use default namespace of age catalog. A function can be used outside the name space and this can be done by adding namespace before the function name.
Syntax:
namespace_name.function_name
Query:
SELECT *
FROM cypher('graph_name', $$
RETURN pg_catalog.square(5)
$$ as (result agtype);
The above query will return square of the number 5.
Top comments (0)