skip to Main Content

I am currently working on a social network graph using Apache AGE with PostgreSQL, where I have vertices representing users and edges representing the relationships between them (e.g., "friend" or "follower"). Each vertex has several properties, such as user_id, name, email, and age, while edges have properties like relationship_type and since.

I would like to know how I can update a specific property of a vertex (e.g., changing the email of a user) without affecting other properties or connected entities in the graph.

I have a vertex with the following properties:

{
  "user_id": 1,
  "name": "Alice",
  "email": "[email protected]",
  "age": 30
}

Alice updates her email address, so I need to update the email property of the vertex to "[email protected]" while leaving other properties and connected edges unchanged.
Could you please provide an example of how to achieve this using AGtype in Apache AGE?

Additionally, are there any performance considerations or best practices I should be aware of when updating AGtype properties in a large-scale graph?

Thank you for your help!

3

Answers


  1. You can use the SET clause to change properties of a query. In your example :

    SELECT * FROM 
    cypher('<your_graph>' $$ 
    MATCH (u {name: 'Alice', email: '[email protected]'})
    SET u.email = '[email protected]'
    RETURN u $$)
    AS (u agtype);
    

    More on updating properties here

    Login or Signup to reply.
  2. One way to do this would be:

    UPDATE user SET properties = properties || '{"email": "[email protected]"}'::agtype WHERE user_id = 1;
    
    Login or Signup to reply.
  3. To update the properties you can use this below command:

        UPDATE mygraph SET properties = properties || '{"email": "[email protected]"}'::agtype
    WHERE id = 1;
    

    As far as the best practices and good techniques for a a better performance is concerned, I would recommend the following things:

    • Try to use the indexes, this help to drastically improve the performance.
    • Secondly, Try to minimize the duplication of the data and try to remove any redundant and excessive repetitive stuff and build a good maintainance strategy.
    • Lastly, try to keep check on the utilization and allocation of the resources.

    I hope this will help you. Feel free to ask anything, anytime.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search