creating dynamic updates in Agensgraph via Cypher

50 Views Asked by At

trying to create a function like :-

addChild(parent graphid,child graphid,relationship text,direction text)

merge(parent)-[r:f(relationship)]->(child) return id(r);

with a typical cal :

relid=addChild(id(a),id(b),'has','U') -- where U means up child to parent

Question is, without a very tedious switch statement , how do I associate a text version of the relationship, or edge type, with an actual edge type?

1

There are 1 best solutions below

0
On

Took a bit of messing around and the syntax seems a bit last-minute but this works :

return query execute format('match(p) where id(p)=%s with p match(c) where id(c)=%s with p,c merge(p)-[r:%s]->(c)  return id(r);',parent,child,reltype);

Where parent and child are graph ids and reltype is text;