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.

  1. Developer's Note:
  2. Void and Scalar-Value functions only. Set returning functions are not currently supported.

Create Function

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

Query

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

Results

name
“Apache Con 2021”
1 row