You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@age.apache.org by "safi50 (via GitHub)" <gi...@apache.org> on 2023/05/14 09:27:29 UTC

[GitHub] [age] safi50 commented on issue #918: How to add multiple edges in single query faster?

safi50 commented on issue #918:
URL: https://github.com/apache/age/issues/918#issuecomment-1546854491

   Another way to do so is by using `UNWIND`.  Suppose I have 6 vertices: 
   
   ```
   (:Person {name: 'Joe', title: 'Developer'}),  
   (:Person {name: 'Andy', title: 'Manager'}),         
   (:Person {name: 'Hakan', title: 'Protector'}),     
   (:Person {name: 'Leyla', title: 'Assistant'}), 
   (:Person {name: 'Sofi', title: 'Explorer'}),          
   (:Person {name: 'Ian', title: 'Scientist'})   
   ```
   Now, I can use `UWIND` to create edges for these with a single cypher query. See example below: 
   
   ```
   SELECT * FROM cypher('test', $$
   WITH [
     {source: 'Joe', target: 'Andy', weight: 2},
     {source: 'Andy', target: 'Hakan', weight: 3},
     {source: 'Andy', target: 'Leyla', weight: 1},
     {source: 'Hakan', target: 'Sofi', weight: 4},
     {source: 'Sofi', target: 'Ian', weight: 2}
   ] AS edges
   
   UNWIND edges AS edge
   
   MATCH (source:Person {name: edge.source})
   MATCH (target:Person {name: edge.target})
   
   CREATE (source)-[rel:WORKS_WITH {weight: edge.weight}]->(target) RETURN rel $$) as ( a agtype);
   ```


-- 
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.

To unsubscribe, e-mail: dev-unsubscribe@age.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org