JoshInnis commented on issue #50: URL: https://github.com/apache/incubator-age/issues/50#issuecomment-819722171
There are currently two ways to import data into a graph in AGE via sql. Both of these ways are new and not in 0.3.0. So you will need to download master to be able to do this. They will be in the 0.4.0 release, which should be released shortly. 1. Prepared Statements: https://www.postgresql.org/docs/11/sql-prepare.html. So you would need to format the query as ```` PREPARE create_person AS SELECT * FROM cypher('graph_name', $$ CREATE (:Person {name: $name, title: $title}) $$, $1) as (n agtype); ```` Then to run the basic example you would do ```` EXECUTE create_person('{"name": "Andres", "title": "Developer"}'); ```` This would work for one row, so you would need a cursor to import the whole table 2. Dynamic SQL in a pl/pgSQL Function You could make a pl/pgsql function that takes in your arguments of name and title and creates a node, such as ```` CREATE OR REPLACE FUNCTION public.create_person(name text, title text) RETURNS void LANGUAGE plpgsql VOLATILE AS $BODY$ BEGIN load 'age'; SET search_path TO ag_catalog; EXECUTE format('SELECT * FROM cypher(''graph_name'', $$CREATE (:Person {name: %s, title: %s})$$) AS (a agtype);', quote_ident(name), quote_ident(title)); END $BODY$; ```` Then you could call the function like: ```` SELECT public.create_person(sql_person.name, sql_person.title) FROM sql_schema.Person AS sql_person; ```` This would create a vertex for every row in sql_schema.Person. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected]
