Consider the example as follow :
SQL command for creating table and INSERT into table
create table person (
person_uid SERIAL NOT NULL PRIMARY KEY,
person_name VARCHAR(50) NOT NULL
);
-- INSERT INTO person
insert into person ( person_name ) values ('Fernanda');
insert into person ( person_name ) values ('Moontasir');
insert into person ( person_name ) values ('Sanjida');
insert into person ( person_name ) values ('Fahmida');
Load AGE
load 'age';
SET search_path TO ag_catalog;
Prepare statement
See the doc for more info about prepare statement
PREPARE create_person AS
SELECT *
FROM cypher('graph_name', $$
CREATE (:Person {name: $name})
$$, $1) as (n agtype);
Dynamic SQL in a pl/pgSQL Function
You could make a pl/pgsql function that takes in your arguments of name and other property and creates a node, such as
CREATE OR REPLACE FUNCTION public.create_person(name text)
RETURNS void
LANGUAGE plpgsql
VOLATILE
AS $BODY$
BEGIN
EXECUTE format('SELECT * FROM cypher(''graph_name'', $$CREATE (:Person {name: %s})$$) AS (a agtype);', quote_ident(name));
END
$BODY$;
Now you can call the function
SELECT public.create_person(sql_person.person_name)
FROM person AS sql_person;
This would create a vertex for every row in person.
Alternatively
As the graph relation I want can vary in different situation you can use the python or any other driver to implement your own logical graph database.