1

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": "alice@example.com",
  "age": 30
}

Alice updates her email address, so I need to update the email property of the vertex to "alice.new@example.com" 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!

7 Answers7

1

To update the properties you can use this below command:

    UPDATE mygraph SET properties = properties || '{"email": "alice.new@example.com"}'::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.

0

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: 'alice@example.com'})
SET u.email = 'alice.new@example.com'
RETURN u $$)
AS (u agtype);

More on updating properties here

0

One way to do this would be:

UPDATE user SET properties = properties || '{"email": "alice.new@example.com"}'::agtype WHERE user_id = 1;
tokamak32
  • 27
  • 7
0

To update the specific property of a vertex, you could use the AGtype language and connected entities in the graph.

UPDATE users
SET properties = properties || '{"email": "alice.new@example.com"}'
WHERE id = 1;

I hope this will help.

0

In order to update the specific property of a vertex without any consequence on other properties or entities in the graph one of the ways is that you can use agtype queries like, e.g SET clause:

UPDATE user SET properties = properties || '{"email": "alice.new@example.com"}'::agtype WHERE user_id = 1;

The documentation here is quite helpful.

0

If you want to update the email property of the vertex to "alice.new@example.com" while leaving other properties and connected edges unchanged, you should use SET and UPDATE clause.

Here's the example:

UPDATE users
SET properties = jsonb_set(properties, '{email}', '"alice.new@example.com"')
WHERE id : 1;
adil shahid
  • 125
  • 4
0
UPDATE user
SET properties = merge(properties, {"email": "alice.new@example.com"})
WHERE id = 1;

Check out the official documentation.