skip to Main Content

Is there any possible way to change the current label of a vertex or an edge? For example, if I create a graph to store movies and series and then create the following vertex:

SELECT * FROM cypher ('visual_arts', $$
CREATE (v:Movie {title: "The Last of Us", episodes: 4, seasons: 1, main_actors: ["Pedro Pascal", "Bella Ramsey"]})
RETURN v $$) as (v agtype);

And then I want to correct this vertex by changing the label to "Series" instead of "Movie". How can I do that?

3

Answers


  1. In current version of AGE, we cannot update label of any vertex or edge.

    To do so, the best way is to introduce a new property UpdatedLabel and set it to Series.
    You can do so by:

    SELECT * FROM cypher('visual_arts', $$
    MATCH (v:Movie)
    SET v.UpdatedLabel = "Series" RETURN v
    $$) as (v agtype);
    

    Now you can retrieve the Series by using:

    SELECT * FROM cypher('visual_arts', $$
    MATCH (v:Movie)
    where v.UpdatedLabel = "Series" RETURN v
    $$) as (v agtype);
    
    Login or Signup to reply.
  2. Unfortunately, we don’t have update label functionality in Apache-age but sooner we will be having that functionality.

    It will most prolly be on the same pattern as it works in cypher queries in Neo4j like

    1. first match the node you want to update label for
    2. then delete the previous label for the node
    3. then add the new label for the node

    Note: node here refers to vertex or edge

    For example: if we have a node with label "Engine" and want to update it to "EnginePower" then in the following way we can do that in cypher Neo4j

    MATCH (c:Car)-[r]-(e:Engine)
    REMOVE e:Engine
    SET e:EnginePower
    RETURN e
    

    For the same if we want to add functionality in apache-age then it can be something in the following manner

    SELECT * FROM cypher('graph_name', $$
    MATCH (c:Car)-[r]-(e:Engine)
    REMOVE e:Engine 
    SET e:EnginePower 
    RETURN e
    $$) as (e agtype);
    
    Login or Signup to reply.
  3. It is not possible to directly change the label of a vertex or an edge in AGE. Alternatively, you can create a new vertex or edge with the desired label and properties and delete the old vertex or edge.

    Here’s an example of how you can achieve this in AGE for the vertex you created:

    • Create a new vertex with label "Film" and copy over properties
    SELECT * FROM cypher('mygraph', $$
    MATCH (m:Movie {title: "The Last of Us"})
    CREATE (f:Film {title: v.title, episodes: v.episodes, seasons: v.seasons, main_actors: v.main_actors})
    RETURN f $$) AS (f agtype);
    
    • Delete the old "Movie" vertex
    SELECT * FROM cypher('mygraph', $$
    MATCH (v:Movie {title: "The Last of Us"})
    DETACH DELETE v $$) AS (v agtype);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search