SQL In Cypher

AGE does not support SQL being directly written in Cypher. However with user defined functions you can write sql queries and call them in a cypher command.

Developer's Note:

Void and Scalar-Value functions only. Set returning functions are not currently supported.

Create Function

CREATE OR REPLACE FUNCTION public.get_event_year(name agtype) RETURNS agtype AS $$
	SELECT year::agtype
	FROM history AS h
	WHERE h.event_name = name::text
	LIMIT 1;
$$ LANGUAGE sql;

Query

SELECT * FROM cypher('graph_name', $$
	MATCH (e:event)
	WHERE e.year < public.get_event_year(e.name)
	RETURN n.name
$$) as (n agtype);

Results

name
"Apache Con 2021"
1 row