全部產品
Search
文件中心

PolarDB:SQL在Cypher中的使用

更新時間:Jan 10, 2025

AGE不支援在Cypher中直接編寫SQL。但可以通過定義自訂函數,編寫SQL查詢並在Cypher命令中調用它們。

建立函數

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;

查詢:

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

返回結果如下:

 n 
-------------------
 "Apache Con 2021"
(1 row)