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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to