Created
March 6, 2024 11:16
-
-
Save mingfang/d89a61add276efad92f176d8da0addb5 to your computer and use it in GitHub Desktop.
Apache AGE load data using SQL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE EXTENSION IF NOT EXISTS age; | |
LOAD 'age'; | |
SET search_path = ag_catalog, "$user", public; | |
-- Apache AGE load_sql | |
CREATE OR REPLACE FUNCTION public.load_sql(query agtype) RETURNS SETOF agtype AS $$ | |
BEGIN | |
RETURN QUERY EXECUTE FORMAT($sql$ | |
WITH query AS (%s) | |
SELECT agtype_build_list(query) | |
FROM query | |
$sql$, query::text); | |
END | |
$$ LANGUAGE plpgsql VOLATILE; | |
-- sample | |
SELECT * FROM cypher('playground', $$ | |
WITH public.load_sql(' | |
SELECT * FROM movies | |
') AS rows | |
UNWIND rows AS row | |
MERGE (v:MOVIE {id: row.title}) | |
SET v=row | |
RETURN v | |
$$) AS (v agtype); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment